필터 지우기
필터 지우기

how to make subplots of data in two different loops?

조회 수: 1 (최근 30일)
Robert Hitchings
Robert Hitchings 2015년 7월 14일
댓글: Walter Roberson 2015년 7월 15일
The code below creates a bar graph for each day in my data and a line graph for each day in my data but at different sizes. I utilize 'pause' to see each day separately to cycle through the days. I'd like to put figure 1 and figure 2 in the same window to see both at the same time, is there any way to do this while still being able to sue pause?
load ('JB1_dep1_top.mat')
time=time((1:6048));
oxconc=oxconc(1:6048);
temp=temp(1:6048);
oxsat=oxsat(1:6048);
salt=salt(1:6048);
dt=5/60;
do_dt=diff(oxconc);
airsea=(1-(oxsat(1:end-1)+oxsat(2:end))/200)*0.5*dt;
oxflux=(do_dt*depth)-airsea; %(g mL^-1 d^-1);
oxflux=[oxflux;NaN];
oxfluxmean=[];
%hourly oxygen fluxes (g
for ii=1:12:length(oxflux);
tempmean=nanmean(oxflux(ii:ii+11));
oxfluxmean=[oxfluxmean;tempmean];
end
for ii=1:24:length(oxfluxmean)
day=oxfluxmean(ii:ii+23);
figure(1);
bar(day);
xlim([1,24])
title('Mean Hourly O2 flux');
xlabel('Hour')
ylabel('O2 flux')
pause;
end
for i=1:288:length(time);
oxconc_dy=oxconc(i:i+287);
time_dy=time(i:i+287);
figure (2);
plot(time_dy,oxconc_dy);
datetick('x',2,'keepticks');
title('Oxygen Concentraion Over Time');
xlabel('time');
ylabel('oxygen concentration');
pause;
end

답변 (1개)

Walter Roberson
Walter Roberson 2015년 7월 14일
You cannot put two figures in the same window, as "figure" and "window" are the same thing in MATLAB. You can, though, put two axes in the same figure.
figure(1);
ax1 = subplot(1,2,1);
ax2 = subplot(1,2,2);
for ii=1:24:length(oxfluxmean)
day=oxfluxmean(ii:ii+23);
bar(ax1, day);
xlim(ax1, [1,24])
title(ax1, 'Mean Hourly O2 flux');
xlabel(ax1, 'Hour')
ylabel(ax1, 'O2 flux')
pause;
end
for i=1:288:length(time);
oxconc_dy=oxconc(i:i+287);
time_dy=time(i:i+287);
plot(ax2, time_dy, oxconc_dy);
datetick(ax2, 'x',2,'keepticks');
title(ax2, 'Oxygen Concentraion Over Time');
xlabel(ax2, 'time');
ylabel(ax2, 'oxygen concentration');
pause;
end
  댓글 수: 2
Robert Hitchings
Robert Hitchings 2015년 7월 14일
Sorry, I should have made this a little more clear. I want it to appear something this code:
figure(1)
subplot(1,2,1);
bar(day);
xlim([1,24])
title('Mean Hourly O2 flux');
xlabel('Hour')
ylabel('O2 flux')
pause;
subplot(1,2,2);
plot(time_dy,oxconc_dy);
datetick('x',2,'keepticks');
title('Oxygen Concentraion Over Time');
xlabel('time');
ylabel('oxygen concentration');
pause;
but have the pause work for both plots. Currently, if not inside their respective loops, it only works for the first plot and holds the second at what would be the final iteration in the second loop
Walter Roberson
Walter Roberson 2015년 7월 15일
Just remove the first "pause" ?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by