multiple subplots in a figure

1 view (last 30 days)
siavash
siavash on 8 May 2011
I am trying to plot multiple subplots in a single figure. But some weired problem exists and some subplots are deleted !! or maybe there exists other methods to add multiple subplots.
nx=20; ny=10;
ngrids=nx*ny;
figure;
for i=1:ngrids
y=ceil((i)/nx);
x=i-(y-1)*nx;
subplot(nx,ny,i);
axis square;
set(gca,'xtick',[],'ytick',[],'Position', [((-1/nx)+x/nx) ((1-1/ny)-(y-1)/ny) (1/nx) (1/ny)]);
text(.5,.5,int2str(i),'FontSize',9,'HorizontalAlignment','center')
pause(0.001);
end

Answers (1)

Jarrod Rivituso
Jarrod Rivituso on 8 May 2011
Similar question:
Main point there -> use "axes" instead of "subplot" if you are going to modify the position manually anyway.
nx=20;
ny=10;
ngrids=nx*ny;
figure;
for i=1:ngrids
y=ceil((i)/nx);
x=i-(y-1)*nx;
axes
axis square;
set(gca,'xtick',[],'ytick',[],'Position', [((-1/nx)+x/nx) ((1-1/ny)-(y-1)/ny) (1/nx) (1/ny)]);
text(.5,.5,int2str(i),'FontSize',9,'HorizontalAlignment','center')
pause(0.001);
end

Community Treasure Hunt

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

Start Hunting!