How to work with annotation?

1 visualizzazione (ultimi 30 giorni)
Prince Chowdhury
Prince Chowdhury il 30 Mar 2018
Commentato: Rik il 2 Apr 2018
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!!

Risposte (1)

Rik
Rik il 30 Mar 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 Commento
Rik
Rik il 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.

Accedi per commentare.

Categorie

Scopri di più su Entering Commands in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by