How to stop the subplot at different time loop
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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)
0 commentaires
Réponses (1)
Neuropragmatist
le 14 Août 2019
Modifié(e) : Neuropragmatist
le 14 Août 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
Hope this helps,
M.
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!