How to stop the subplot at different time loop

조회 수: 10 (최근 30일)
Obaja Triputera Wijaya
Obaja Triputera Wijaya 2019년 8월 14일
댓글: Obaja Triputera Wijaya 2019년 11월 13일
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

답변 (1개)

Neuropragmatist
Neuropragmatist 2019년 8월 14일
편집: 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;
% 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.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by