フィルターのクリア

Dot notation with multiple dots in it

12 ビュー (過去 30 日間)
Hugo FOTIA
Hugo FOTIA 2021 年 11 月 2 日
コメント済み: Hugo FOTIA 2021 年 11 月 4 日
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 !

採用された回答

Steven Lord
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'.
  1 件のコメント
Hugo FOTIA
Hugo FOTIA 2021 年 11 月 4 日
Thank you for the answer !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by