How to include text in a running figure

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!

Réponses (2)

KSSV
KSSV le 5 Oct 2020
Modifié(e) : KSSV le 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 commentaire

Alison Spera
Alison Spera le 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!

Connectez-vous pour commenter.

Ameer Hamza
Ameer Hamza le 5 Oct 2020
Modifié(e) : Ameer Hamza le 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 commentaires

Alison Spera
Alison Spera le 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 le 6 Oct 2020
How are you trying to make the video? What type of issue occurs?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by