How to work with annotation?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Rik
am 30 Mär. 2018
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 Kommentar
Rik
am 2 Apr. 2018
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.
Siehe auch
Kategorien
Mehr zu Entering Commands finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!