Effacer les filtres
Effacer les filtres

how to make subplots of data in two different loops?

2 vues (au cours des 30 derniers jours)
Robert Hitchings
Robert Hitchings le 14 Juil 2015
Commenté : Walter Roberson le 15 Juil 2015
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

Réponses (1)

Walter Roberson
Walter Roberson le 14 Juil 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 commentaires
Robert Hitchings
Robert Hitchings le 14 Juil 2015
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 le 15 Juil 2015
Just remove the first "pause" ?

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by