Change from set notation to dot notation

조회 수: 9 (최근 30일)
KostasK
KostasK 2019년 7월 30일
편집: Stephen23 2019년 7월 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.

채택된 답변

Stephen23
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."
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개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by