'Set' function applied on handle and vector of handle

2 views (last 30 days)
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!

Accepted Answer

Greg
Greg on 12 Apr 2013
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.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!