Change from set notation to dot notation
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Stephen23
2019-7-30
编辑:Stephen23
2019-7-30
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Labels and Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!