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!