How to include text in a running figure
17 views (last 30 days)
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!
0 Comments
Answers (2)
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
See Also
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!