How to stop the subplot at different time loop

9 views (last 30 days)
I have a function that loop trough time and I would like to subplot the result at a different time so that I can see the differrence.
for example, the function start t = 0 and finish at t = 10. For the first subplot I want it stop at t = 5 and second subplot I want it stop at t = 10.
Anyway, for my case I am using the surf function to plot my graph (it is 2D analysis)
Capture.JPG

Answers (1)

Neuropragmatist
Neuropragmatist on 14 Aug 2019
Edited: Neuropragmatist on 14 Aug 2019
By time do you just mean loops? Like this:
figure
for i = 1:20
x = rand(100,1);
if i==1
subplot(1,2,1)
boxplot(x);
title('loop 1')
elseif i==10
subplot(1,2,2)
boxplot(x);
title('loop 10')
end
end
If you mean actual runtime of the function you can do something similar with tic and toc, but you have to make sure you only plot each plot once:
figure
tic; % start timer
times_to_stop = [1 3 7 10]; % times to plot at in seconds
plot_vector = true(size(times_to_stop)); % we will set these to false as we plot things
for i = 1:101
% some operation you want to complete goes here
x = rand(100,1)*100;
% your operation finishes here
tnow = toc;
if any(times_to_stop<tnow & plot_vector)
subplot(1,length(times_to_stop),find(plot_vector,1,'first'))
boxplot(x);
title(sprintf('time = %.1f',toc))
plot_vector(find(plot_vector,1,'first')) = false; % now we have plotted it we don't want to replot it on future loops
end
pause(.1)
end
untitled.png
Hope this helps,
M.

Categories

Find more on 2-D and 3-D Plots 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!