Use annotation function changing the string dinamycally

9 次查看(过去 30 天)
Hi,
I want to create a text in a figure but outside the axis, but it has to change with the time according to some pressure sensors. I am using "annotation" function:
loop:
steps=steps+1;
txt = ['Steps number: ' num2str(step_number) ' units'];
annotation('textbox',[.9 .5 .1 .2],'String',txt,'EdgeColor','none');
The issue is that the value it's being overlapped each iteration. Could someone help please? Thanks

采纳的回答

Rik
Rik 2019-2-7
Create the annotation once, and then only change the string property inside the loop.
figure(1)
txt='';
h_annot=annotation('textbox',[.9 .5 .1 .2],'String',txt,'EdgeColor','none');
for steps=1:5
step_number=steps;
txt = sprintf('Steps number: %d units',step_number);
set(h_annot,'String',txt)
drawnow%force graphics update, pause(0.001) will work as well
for k=1:1e6
1+1;%have some calculation to simulate your actual processing time
end
end
close(1)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by