Change from set notation to dot notation
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
KostasK
am 30 Jul. 2019
Bearbeitet: Stephen23
am 30 Jul. 2019
Hi all,
Just in order to keep uniformity in my code, I would like to know if its possible to change the below expression from a 'set' notation to a dot notation.
Specifically, I have a plot were I am plotting a vector (x) with a matrix (y), hence I am getting multiple lines plotted at once. Obviously, where I desire to update the YData with my new matrix 'y1', i am unable to simply use the dot notation in the form seen below, since 'p' is consistent of 3 elements and 'y1' is a matrix:
% Plot of x & y data, where x is 1x100 and y is 3x100
p = plot(x,y) ;
% Update plot of x & y data with y1 vector, the same size as y
p.YData = y1 ;
%Error: Expected one output from a curly brace or dot indexing expression, but there were 3 results.
So the way which I found that works is:
% Plot of x & y data, where x is 1x100 and y is 3x100
p = plot(x,y) ;
% Update plot of x & y data with y1 vector, the same size as y
set(p, {'YData'}, num2cell(y1,2) )
% No Error
Hence, is there a way to represent the above with a dot notation?
Thanks for your help in advance,
KMT.
0 Kommentare
Akzeptierte Antwort
Stephen23
am 30 Jul. 2019
Bearbeitet: Stephen23
am 30 Jul. 2019
The MATLAB documentation explains that dot-notation only applies to scalar objects:
For non-scalar objects the documentation shows set (as you show in your question) or indexing (i.e. to reference a scalar object). This is also explained in the introduction to the new handle graphics: "Use the set and get functions to access properties for an array of objects."
https://www.mathworks.com/help/matlab/graphics_transition/graphics-handles-are-now-objects-not-doubles.html
So you could do something like this:
for k = 1:numel(p)
p(k).YData = y1(k,:);
end
or use set as you show in your question.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Labels and Annotations 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!