Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Topic: plot multiple figures, each with subplots, in nested for loops
Replies: 5   Last Post: Dec 20, 2013 11:27 AM

 Messages: [ Previous | Next ]
 Derek Goring Posts: 3,892 Registered: 12/7/04
Re: plot multiple figures, each with subplots, in nested for loops
Posted: Dec 19, 2013 4:54 PM

On Friday, December 20, 2013 10:32:15 AM UTC+13, Thomas wrote:
> I have a three layer nested for loop situation, I want to generate three figures in for loop "3" where each iteration of for loop "2" inserts subplots into each of the three and each iteration of for loop "1" generates its own set of three figures in for loop "3" to be populated with the subplots from loop "2".
>
>
>
> I have code structured like this:
>
>
>
> rawdata={'file1' 'file2' 'file3'};
>
> field=[280 300 320];
>
> vars=[1 2 3 4];
>
> varst=[0,1,2,3];
>
> varen=[2,3,4,5];
>
> index=6;
>
> for a=1:length(vars)
>
> for b=1:index
>
> linc(a)=(varen(a)-varst(a))/index;
>
> xd=vars;
>
> xd(b)=((b-1)*linc(b))+varst(b);
>
> for c=1:length(field)
>
> [data]=processing(rawdata{c});
>
> [spec freq]=function(vars,field(c))
>
> figure(c*a);
>
> subplot(3,3,b);plot(freq,spec);
>
> subplot(3,3,8);plot(freq,data);
>
> end
>
> end
>
> end
>
> This works except there are repeats of the figure index at certain combinations of a and c (for example: when a=2 and c=1, this overwrites the figure for a=1 and c=2.) I've tried a bunch of methods for getting around this but nothing has worked. Does anyone know how to do this?
>
>
>
> Thanks!

Don't bother numbering the figures at all.
Matlab will figure it out OK each time to say:
figure;

Date Subject Author
12/19/13 Thomas
12/19/13 Derek Goring
12/19/13 Thomas
12/19/13 Curious
12/20/13 Thomas
12/19/13 Curious