Borrar filtros
Borrar filtros

Dot notation with multiple dots in it

5 visualizaciones (últimos 30 días)
Hugo FOTIA
Hugo FOTIA el 2 de Nov. de 2021
Comentada: Hugo FOTIA el 4 de Nov. de 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 !

Respuesta aceptada

Steven Lord
Steven Lord el 2 de Nov. de 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'.

Más respuestas (0)

Categorías

Más información sobre Software Development Tools en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by