How to quickly update plotted texts in axes?
8 ビュー (過去 30 日間)
古いコメントを表示
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)?
0 件のコメント
採用された回答
Walter Roberson
2021 年 2 月 16 日
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 件のコメント
Walter Roberson
2021 年 2 月 16 日
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!