Reputation: 863
I create figures with 5x3 subplots, every iteration, another 3 figures is added per column and every iteration, the previous three plots shrink a little more.
This is my code:
for i=1:4%for every station
figure
for j=1:sSelect %for every storm
Hm0=eval(strcat('Hm0',Wavenames(i),'C'));%create data
Tz=eval(strcat('Tz',Wavenames(i),'C'));
Tp=eval(strcat('Tp',Wavenames(i),'C'));
Ti=numericdates.(Wavenames(i));
ix=Ti>Selectnum(j,1)-numMore & Ti<Selectnum(j,2)+numMore; %index of dates numMore hours before and after the storm
Hm0Plot=Hm0(ix); %create data that needs to be plotted
TzPlot=Tz(ix);
TpPlot=Tp(ix);
TPlot= datetime(Ti(ix),'ConvertFrom','datenum');%dates
if ~isempty(TPlot)
subplot(3,5,j)
plot(TPlot,Hm0Plot)
xlabel('Date')
ylabel('Hm0 (m)')
xtickformat('dd-MM-yyyy HH:mm:ss')
subplot(3,5,j+5)
plot(TPlot,TzPlot)
xtickformat('dd-MM-yyyy HH:mm:ss')
xlabel('Date')
ylabel('Tz0 (1/s)')
subplot(3,5,j+10)
plot(TPlot,TpPlot)
xtickformat('dd-MM-yyyy HH:mm:ss')
xlabel('Date')
ylabel('Tp (1/s)')
suptitle(Wavenames(i))
end
end
end
This creates 4 figures that all have the same problem and look like this:
How do I make all the subplots have the same size?
Upvotes: 1
Views: 151
Reputation: 863
This is because the command suptitle
is in the loop. If I put it outside of the loop, it works.
for i=1:4%for every station
figure
for j=1:sSelect %for every storm
Hm0=eval(strcat('Hm0',Wavenames(i),'C'));%Hm0BanyulsC
Tz=eval(strcat('Tz',Wavenames(i),'C'));%TzBanyulsC
Tp=eval(strcat('Tp',Wavenames(i),'C'));%TpBanyulsC
Ti=numericdates.(Wavenames(i));
ix=Ti>Selectnum(j,1)-numMore & Ti<Selectnum(j,2)+numMore; %index of dates numMore hours before and after the storm
Hm0Plot=Hm0(ix);
TzPlot=Tz(ix);
TpPlot=Tp(ix);
TPlot= datetime(Ti(ix),'ConvertFrom','datenum');
if ~isempty(TPlot)
subplot(3,5,j)
plot(TPlot,Hm0Plot)
xlabel('Date')
ylabel('Hm0 (m)')
xtickformat('dd-MM-yyyy')
% title(strcat('Storm',string(j)))
subplot(3,5,j+5)
plot(TPlot,TzPlot)
xtickformat('dd-MM-yyyy')
xlabel('Date')
ylabel('Tz0 (1/s)')
subplot(3,5,j+10)
plot(TPlot,TpPlot)
xtickformat('dd-MM-yyyy')
xlabel('Date')
ylabel('Tp (1/s)')
end
end
suptitle(Wavenames(i))
end
Upvotes: 2