Update multiple objects Position(2) at once

3 次查看(过去 30 天)
Hello,
I want to update at once all the Position(2) of some graphic objects that are on different tiles of a same figure.
I am not sure what would be the best way - I assume using a loop would work but is not ideal. I wish I could use the linkprop function, but so far I have been able to use it only to link the complete position, instead of linking only the second element of Position.
I also have tried to use arrayfun to edit only the second element of position, but my objects are stored in a graphic array that has empty elements bacause there are not the same number of object per tile.
Here is a simplified example of my problem. I would like to change all the T.Position(2) at once:
% preallocate arrays to store my future objects
T = gobjects(3,4);
ax = gobjects(1,3);
f = figure(1);
t = tiledlayout(3,1);
for i = 1:3
ax(i) = nexttile; hold on;
plot([0 10],[1 5]);
for j = 1:i
T(i,j) = text(ax(i), j*2, 1, 'X'); % <-- objects which position needs to be updated later
end
end
Any thoughts or ideas are welcome, including suggestions concerning how to store my objects in a better way! Thank you!

采纳的回答

Rik
Rik 2025-1-17
A loop is actually the best way. Using arrayfun will only disguise the loop and cost you performance. Interestingly, cellfun with char inputs is faster than a for loop, but with a function handle (or anonymous function) is slower than a loop.
It would have been nicer to link the properties, but unfortunately, you can't link only part of a property.
What you might try (I haven't tested this), is to use panels instead of tiles. That way the Position property is relative to the panel (since that is the parent), which means the relative position is the same. This still wouldn't solve the issue of one axes containing more objects than another one.
  1 个评论
L Oc
L Oc 2025-1-20
Thank you for your clear explanations! I ended up making a loop that works just fine, even if I am a little frustrated not to have a more elegant solution :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by