Filter löschen
Filter löschen

Dot notation with multiple dots in it

5 Ansichten (letzte 30 Tage)
Hugo FOTIA
Hugo FOTIA am 2 Nov. 2021
Kommentiert: Hugo FOTIA am 4 Nov. 2021
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 !

Akzeptierte Antwort

Steven Lord
Steven Lord am 2 Nov. 2021
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'.

Weitere Antworten (0)

Kategorien

Mehr zu Software Development Tools finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by