How to include text in a running figure
Afficher commentaires plus anciens
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)
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
le 5 Oct 2020
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
le 5 Oct 2020
Ameer Hamza
le 6 Oct 2020
How are you trying to make the video? What type of issue occurs?
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!