How to work with annotation?
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
Is it possible to add annotation within a for loop so that the previous annotation is replaced once the new annotation is added? For example, for i = 1:100 annotation('textbox', [0, 0.5, 0, 0],'FitBoxToText','On','FontSize',25,'Tag', num2str(i), 'string', num2str(i));
this code currently piles up all the annotation on top of each other in the figure plot but what I am looking for is as the value of i steps through to 2 from 1 then the annotation at i = 1 should be replaced by i = 2. Only one annotation should be visible in the plot per iteration.
Could someone please help...Thanks!!
0 件のコメント
回答 (1 件)
Rik
2018 年 3 月 30 日
The trick is to use the handle to set the String property. You might need a call to drawnow to trigger a graphics update.
figure(1),clf(1)
i=1;
h=annotation('textbox', [0, 0.5, 0, 0],...
'FitBoxToText','On',...
'FontSize',25,...
'Tag', num2str(i),...
'string', num2str(i));
for i=1:5
pause(1)
set(h,'String',num2str(i))
end
1 件のコメント
Rik
2018 年 4 月 2 日
Did this suggestion solve your problem? If so, please consider marking it as accepted answer. It will make it easier for other people with the same question to find an answer, as well as give me reputation points. If this didn't solve your question, please comment with what problems you are still having.
参考
カテゴリ
Help Center および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!