# How to stop the subplot at different time loop

67 ビュー (過去 30 日間)
Obaja Triputera Wijaya 2019 年 8 月 14 日
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)

サインインしてコメントする。

### 回答 (1 件)

Neuropragmatist 2019 年 8 月 14 日

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;
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.

#### 1 件のコメント

Obaja Triputera Wijaya 2019 年 11 月 13 日
Thanks it helps

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!

Translated by