Update multiple objects Position(2) at once
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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!
0 comentarios
Respuesta aceptada
Rik
el 17 de En. de 2025
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!