How to do subplot loop?

46 views (last 30 days)
IGOR RIBEIRO
IGOR RIBEIRO on 29 Mar 2016
Answered: MHN on 29 Mar 2016
Hello, I am making a program to plot figures (variable amount) with three subplots, wherein each subplot is a variable. I could not end the program. I do not know how to loop to plot the variables. For example: I want 24 figures, each with three subplots, each subplot is a variable. Then, the program has to enter in Figure 1, after the subplot 1 and plot the variable 26. Then enter the figure 1, enter the subplot 2 and plot the variable 27. Then enter the figure 1, enter the subplot 3 and plot the variable 28. Log in figure 2, enter the subplot 1 and plot the variable 29 ...Thanks for your help. Below the script to where I could do:
oz1=ncread('outd02test02.nc','o3');
lat=ncread('outd02test02.nc','XLAT');
lat_w=double(lat(:,:,1));
lon=ncread('outd02test02.nc','XLONG');
lon_w=double(lon(:,:,1));
numPlots=0;
for io=26:49;
numPlots=numPlots+1;
end
numFigs = ceil(numPlots/3);
for fi=1:numFigs;
figure
for j=1:3;
s=[0.10 0.65 0.5 0.25;...
0.10 0.38 0.5 0.25;...
0.10 0.11 0.5 0.25];
plotNum = j + 3*(fi-1);
if plotNum <= numPlots
subplot(3,1,j)
h=axesm('mapprojection','miller','geoid',referenceEllipsoid('wgs84'),...
'MapLatLimit',[-3.9329 -1.8822],...
'MapLonLimit',[-61.6249 -59.0311],...
'frame','on','FEdgeColor',[0.1500 0.1500 0.1500],'FFaceColor','w',...
'angleunits','degrees',...
'LabelUnits','degrees','MLabelRound',-2,'PLabelRound',-2,...
'fontname','helvetica',...
'fontweight','bold',...
'origin',[0 0 0],...
'grid','on',...
'parallellabel','on',...
'meridianlabel','on',...
'aspect','normal',...
'flinewidth',1,...
'fontsize',8,...
'mlinelocation',1,...
'plinelocation',0.5);
tightmap
set(h,'visible','off')
for io=26:49; %plot variables
cd G:\IgorCH4_matlab\IGOR_CH4\Programas\ADAM\2008.met13
oz1=ncread('out2008met13.nc','o3');
oz2=double(oz1(:,:,4,io));
surfm(lat_w,lon_w,oz2.*1000); contourcmap('jet',0:1:60)
end
end
end
end

Answers (1)

MHN
MHN on 29 Mar 2016
M = rand(100,72); % make 72 variable to plot
for i=1:24
figure
for j=1:3
subplot(1,3,j)
plot(M(:,i:24:72))
end
end

Categories

Find more on Developing Chart Classes 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!