How can I set the properties for multiple objects created with the plot3 function?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 16 Jan. 2017
Bearbeitet: MathWorks Support Team
am 4 Mai 2023
How can I use the 'set' command to set the "xdata", "ydata", and "zdata" properties of multiple 3D objects created with the "plot3" function?
I am currently attempting to plot 2 independent entities in 3D space, so I've created an appropriate object:
org = plot3(x1,y1,z1,x2,y2,z2);
% ...
% Do some conditional math on (x,y,z) data
% ...
set(org, 'xdata1', x1, 'ydata1', y1, 'zdata1', z1, 'xdata2', x2, 'ydata2', y2, 'zdata2', z2); % Update the appropriate values, based-upon the above Conditional Math.
However, when I attempt to perform this operation, I of course get an error - because "xdata1" is not a Line Property.
Must I use a different command than <set()> to accomplish my goals? If so, what?
Akzeptierte Antwort
MathWorks Support Team
am 2 Mai 2023
Bearbeitet: MathWorks Support Team
am 4 Mai 2023
There are two ways to set the properties of multiple graphics objects.
1. When you create a "plot" or "plot3" object with multiple sets of data, the object becomes a Line array, in which each index of the array contains one of those sets of data. So all of your (x1,y1,z1) data is part of the "org(1)" line, and all of your (x2,y2,z2) data is part of the "org(2)" line.
>> set(org(1),'xdata',x1,'ydata',y1,'zdata',z1);
>> set(org(2),'xdata',x2,'ydata',y2,'zdata',z2);
2. You can also use the "set" command with cell array inputs in order to set values for multiple lines at once. Here, you must define two cell arrays for each property - one containing the property name and one containing the desired value of the corresponding property for each line. This allows you to set the data of all of the lines in a single command, which I believe was your original intent:
>> set(org,{'xdata'},{x1;x2},{'ydata'},{y1;y2},{'zdata'},{z1;z2});
For more information about setting graphics object properties, please refer to the following documentation, which explains both setting a property value for one object, as well as setting property values for multiple objects:
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!