Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Derek Goring

Posts: 3,893
Registered: 12/7/04
Re: plot multiple figures, each with subplots, in nested for loops
Posted: Dec 19, 2013 4:54 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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;





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.