How to include text in a running figure
Show older comments
Hi,
I'm very new to Matlab.
I'm running a 3D simulation that shows erosion on a landscape over time and I'd like it to record on the screen the timestep it's running for each frame so I can reference progress to a specific time.
What is the code I need that allows me to get the figure to display the timestep as it runs?
Any guidance would be much appreciated!
Answers (2)
You can use text/ title with sprintf.
for t = 1:100
plot(rand(1,10)) ;
title(sprintf("time step = %s",num2str(t))) ;
drawnow
end
1 Comment
Alison Spera
on 5 Oct 2020
Ameer Hamza
on 5 Oct 2020
Edited: Ameer Hamza
on 5 Oct 2020
Something like this
t = linspace(0, 2*pi);
y = sin(t);
ax = axes();
ax.XLim = [0 2*pi];
ax.YLim = [-1.5 1.5];
hold(ax);
h = animatedline(ax);
txt = text(pi/6, 1.3, 't=0', ...
'HorizontalAlignment', 'left', ...
'FontSize', 16);
for i = 1:numel(t)
addpoints(h, t(i), y(i));
txt.String = sprintf('t=%.2f', t(i));
drawnow;
end

2 Comments
Alison Spera
on 5 Oct 2020
Ameer Hamza
on 6 Oct 2020
How are you trying to make the video? What type of issue occurs?
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!