Hello all: I have been given a script that includes the following code:
hws = get_param(bdroot, 'modelworkspace');
hws.DataSource = 'MAT-File';
hws.FileName = 'filename_xyz';
hws.saveToSource;
The first three lines I understand, but how does the last line work? It is, or appears to be, a function or command, which I would expect to be "saveToSource(hws)" as the usual function syntax (looking at the help for saveToSource). Is there any documentation on this apparent use of the structure field '.' (dot) as a function?
Thanks in advance for any replies.

 Akzeptierte Antwort

dpb
dpb am 15 Okt. 2019

0 Stimmen

"You can also call a method using dot notation....It is not necessary to pass the object explicitly as an argument when using dot notation. The notation uses the object to the left of the dot and method name."
See <Class Basics> and links therein to the details on class syntax. Again, it's a complaint w/ the form of MATLAB documentation that it is so example based it's hard to find the details of syntax in any one place outlined unequivocally, unfortunately. I've never written a class in anger, but I was aware of the allowable syntax (by osmosis, I presume)...

3 Kommentare

Gerrit
Gerrit am 15 Okt. 2019
Thank you, dpb. I was hoping for some more formal documentation/introduction in the pdf manuals perhaps, but if there isn't much, I'll start with the Class Basics in the help that you recommended.
dpb
dpb am 15 Okt. 2019
I don't really know just how much formal documentation there is on classes other than the descriptive/narrative/example format; I'm an old fogey who only writes procedural code. Since I've retired from the consulting gig, I'm basically just writing for myself so there's no pressure to produce anything "pretty".
The one thing of the dot notation for calling procedures is that unless one instills some sort of naming convention, it is can be difficult to know whether a given line of code is invoking a procedure or referencing a property.
Steven Lord
Steven Lord am 15 Okt. 2019
FYI the dot notation and function notation syntax for calling class methods is documented here.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Identification finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2018b

Gefragt:

am 15 Okt. 2019

Kommentiert:

am 15 Okt. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by