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: Break out of IF statement and return to FOR loop + store the row number where break happened
Replies: 7   Last Post: Nov 6, 2013 12:25 PM

Advanced Search

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

Posts: 25
Registered: 11/26/12
Re: Break out of IF statement and return to FOR loop + store the
Posted: Nov 6, 2013 12:13 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

dpb <none@non.net> wrote in message <l5djuu$d2s$1@speranza.aioe.org>...
> On 11/6/2013 8:23 AM, dpb wrote:
> ...
>

> > Need a second index as well is all...
> >
> > j = 1; k=0; % NB these alias the builtin Matlab i,j...
> > while j <= 100
> > if condition is true
> > do something
> > B(j) = % store outputs
> > j = j + 1;
> > else
> > do something else
> > k=k+1;
> > C(j) = B(i,:);
> > end % if condition
> > end % while loop
> >

> ERRATA:
>
> C(j) = B(i,:);
>
> is
>
> C(k) = B(j,:);
>
> of course. Also, it still will suffer as written w/ never getting past
> that point because j ceases to be updated at that time. The increment
> for j needs to be outside the if...else...end block.
>
> j = 0; k=0; % NB these alias the builtin Matlab i,j...
> while j <= 100
> j = j + 1;
> if condition is true
> do something
> B(j) = % store outputs
> else
> do something else
> k=k+1;
> C(k) = B(j,:);
> end % if condition
> end % while loop
>
> --


Thank you very much for the help and I will try it out!



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.