Search All of the Math Forum:

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

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

 Messages: [ Previous | Next ]
Re: Break out of IF statement and return to FOR loop + store the
Posted: Nov 6, 2013 12:13 PM

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!

Date Subject Author