'Set' function applied on handle and vector of handle

조회 수: 2 (최근 30일)
Greg
Greg 2013년 4월 12일
Hi everyone!
Here is a quick shot of a current optimization problem: Let's assume we have a vertical vector of handles. Each handle have been produced by executing the 'plot3' function, and each corresponding curve is defined by two points (twice {X Y Z}).
h(1) = plot3([44 55],[0 0],[0 0],'-r'); hold on,
h(2) = plot3([66 77],[0 0],[0 0],'-r');
h(3) = plot3([88 99],[0 0],[0 0],'-r');
h = [h(1); % vector of handle
h(2);
h(3)];
Thus:
get(h(1),'XData')
gives
ans = [44 55]
ie the two x values of the two points of this curve
Then:
set(h(1),'XData',[11 0])
get(h(1),'XData')
gives
ans = [11 0]
Whereas:
set(h,'XData',[[11 0];
[22 0];
[33 0]])
causes
Error using ==> set
Value must be a column or row vector
Here comes trouble, I would like to update all XData properties of each handle in a single command, without making a loop. Is there any solution to that?
Thanks you very much for any kind of help, I am scratching my head on that since days!

채택된 답변

Greg
Greg 2013년 4월 12일
Okay just found it!
A = [11 0;
22 0;
33 0];
set(h,{'XData'},num2cell(A,2))
And by the way thanks Walter, your tip to add {} is equivalent to num2cell. But then {} around 'XData' also have to be added.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by