how to make subplots of data in two different loops?
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Walter Roberson
on 14 Jul 2015
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 Comments
See Also
Categories
Find more on Subplots 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!