子图大小不同

Subplots are different sizes

我用 5x3 子图创建图形,每次迭代,每列添加另外 3 个图形,每次迭代,前三个图缩小一点。

这是我的代码:

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

这创建了 4 个图形,它们都有相同的问题,看起来像这样:

如何使所有子图具有相同的大小?

这是因为命令suptitle在循环中。如果我把它放在循环之外,它就可以工作。

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