How to include text in a running figure

17 views (last 30 days)
Alison Spera
Alison Spera on 5 Oct 2020
Commented: Ameer Hamza on 6 Oct 2020
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)

KSSV
KSSV on 5 Oct 2020
Edited: KSSV on 5 Oct 2020
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
Alison Spera on 5 Oct 2020
Thank you!
It still doesn't portray the passing timesteps but at least I know the code to bring up the title!

Sign in to comment.


Ameer Hamza
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
Alison Spera on 5 Oct 2020
That's what I'm after but when I try to add it to the code it sends the video into a fit haha
But thank you!
Ameer Hamza
Ameer Hamza on 6 Oct 2020
How are you trying to make the video? What type of issue occurs?

Sign in to comment.

Categories

Find more on Entering Commands 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!