How to work with annotation?
조회 수: 2 (최근 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!