Dot notation with multiple dots in it
6 次查看(过去 30 天)
显示 更早的评论
Hello, I need you help in order to understand the dot notation for invocation.
I read in the Matlab doc that
X = setColor(X,'red')
is equivalent to
X = X.setColor('red')
So if I understand well, in order to use a method from an object you can write
object.method(method parameter)
But I have a program looking like this :
x.number.text='number x';
I don’t understand what would be the equivalent in function notation when there is multiple dots in one notation.
Does it means that the object “x” has a method “number” which is also an object having a method “text” ?
So the equivalent notation would be this ?
number.text(x)= 'number x'
or
text(number(x))= 'number x'
And if it is the case, can we create objects and methods just like this ? I tought we needed to create an entire class definition with classdef, properties, methods…
I may be mistaken by my poor knowledge in oriented object programming, but anyway thanks in advance for your help !
0 个评论
采纳的回答
Steven Lord
2021-11-2
Dot has several different meanings in MATLAB. It can be used for method invocation as you mentioned. It can be used for property indexing or struct field indexing as well.
x.number.text='number x';
I interpret this as x being either an object with a property named number or a struct with a field named number. The object or struct stored in x.number has a property named text (if x.number is an object) or a field named text (if x.number is a struct array.) That line of code sets the property or field to the char vector 'number x'.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!