|
On Nov 14, 11:25 am, "vasilis papadourakis" <lal...@mathworks.com>
wrote:
> dpb <n...@non.net> wrote in message <fhabp6$ut2
>
> $...@aioe.org>...
>
>
>
> > vasilis papadourakis wrote:
> > > Hi all,
>
> > > I want to use subplot to plot many subplots.
> > > For example I want to run the following code:
>
> > > for i = 1:4
> > > subplot(2,2,i)
> > > for j = 1:4
> > > subplot(2,2,j);
> > > plot(something);
> > > end
> > > end
>
> > > so that the final figure would have four sets of the
> four
> > > subplots generated by the j loop.. (ie 16 "normal"
> plots)
>
> > > The above code only keeps the last figure ( a figure
> with
> > > 4 "normal" plots).
>
> > > Does anyone know how to solve this problem?
> > > Thank you in advance
>
> > AFAIK, there is no "subsubplot" routine -- you would have
> to create the
> > 16 subplots at the outer level and use the index to the
> proper one as
> > k = (i-1)*4 + j or similar.
>
> > Try the following to see the effect...
>
> > for i=1:4, for j=1:4, k=(i-1)*4+j,subplot(4,4,k),end,end
>
> > --
>
> I was hoping i wouldnt have to do this, thank you anyway..
I gather that the problem is:
(1) You want the numbering in a different order,
so plots 1-4 are in the upper left, 5-8 in the upper
right, etc.
(2) You don't want to have to do the calculation
of k.
To solve this problem, I'd go ahead and write the
layout code once, then just do the function call.
For instance, you could define a "layout" matrix
that specifies exactly the order of the subplots
you want:
layout = ...
[1 2 5 6
3 4 7 8
9 10 13 14
11 12 15 16];
Then the translation function:
subplotno = @(k) find(layout' == k);
And the usage:
for i=1:16
subplot(4,4,subplotno(i));
title( ['plot #', num2str(i)] );
end
That's not the only approach of course. You
could also without too much trouble write
subplotno to take your original (i,j) numbers
and output the correct subplot number.
- Randy
|