what is the difference between set(object​,'property​',value) and object.property = value)

Hello
i'm struggling between using this:
handles.scatM1.XData = handles.M1(:,1);
handles.scatM1.YData = handles.M1(:,2);
and
set(handles.scatM1,'XData',handles.M1(:,1),'YData',handles.M1(:,1))
is there a difference in the way it will interact? is one way a better option?
because i have tried both option and they seems good both.
Thanks

 Akzeptierte Antwort

Using set() is the old way, pre R2014b release I believe. The "handles.scatM1.YData" way is the modern way and makes MATLAB more like other Object Oriented Programs (OOP). Use the "handles.scatM1.YData" way because it's better, simpler, easier, and the way other programming languages do it.

2 Kommentare

I remember reading somewhere that there is a slight difference in speed between the two methods, with the set being slightly faster. It may not be true anymore however.
There is one major difference between the two syntax. The set method can be used in anonymous functions whereas the property assignment cannot due to the prohibition on any kind of assignment:
%works:
setfn = @(value) set(handles.scatM1,'XData', value);
%not allowed:
setfn = @(value) handles.scatm1.XData = value;
One of the most useful features of set / get is the ability to handle arrays of objects.
lists several features that are available using set / get:
  • "You can use the get command if you want to know all the properties of a graphics object"
  • "The set function is useful if you want to know what options are available for a given property. In this case you can call set with the property name but no value for the property."
  • "Another use of set occurs when you need to reference a property from an array of graphics objects. Suppose you have an array of line objects created by the plot command ... You can use the set function to change the colors of all the lines in the array in a single command."

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

Community Treasure Hunt

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

Start Hunting!

Translated by