Borrar filtros
Borrar filtros

How to quickly update plotted texts in axes?

2 visualizaciones (últimos 30 días)
Andreas Nord
Andreas Nord el 16 de Feb. de 2021
Comentada: Andreas Nord el 16 de Feb. de 2021
I am plotting a fairly big amount of patches (100+) together with their 'ids' as strings, in a loop to create an animation.
I am able to update the patches using the set command, since they are all contained in a 1x1 Patch object. I am not able to find something as straight forward for the texts, because they are in a 100x1 array of Text objects.
With a 100x1 array of Text-objects, can I somehow do an array-based update similar to how I can do for my patches (without having to re-plot or loop over each text object)?

Respuesta aceptada

Walter Roberson
Walter Roberson el 16 de Feb. de 2021
Yes, it is possible, but not well known. I end up having to go back to the reference material every time I try to use it.
t(1) = text(0,0.5,'string1');
t(2) = text(.3,0.5,'string2');
set(t,{'string'},{'test1';'test2'}) %notice the column vector of new values
  3 comentarios
Walter Roberson
Walter Roberson el 16 de Feb. de 2021
Indirectly. text() has Position, which is a vector of [x y z]. To update the x separately you need to fetch the original data, update the x, and store back the data.
t(1) = text(0,0.5,'string1');
t(2) = text(.3,0.5,'string2');
set(t,{'string'},{'test1';'test2'}) %notice the column vector of new values
P = cell2mat(get(t, 'Position'));
P(:,1) = [0.2; 0.6]; %vector of new x data
P = num2cell(P,2);
set(t, {'Position'}, P)
The get(), transfer to/from cell, and set(), could be simplified to a simple set() if you are changing both x and y data at the same time; just remember to toss a z coordinate (0 if appropriate) in at the same time.
The num2cell() trick might come in handy for you if you have an array of coordinates.
Andreas Nord
Andreas Nord el 16 de Feb. de 2021
works like a charm, thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Object Properties 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!

Translated by