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: Variables outside a while loop
Replies: 3   Last Post: Mar 7, 2014 10:08 PM

Advanced Search

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

Posts: 2,192
Registered: 12/6/04
Re: Variables outside a while loop
Posted: Mar 7, 2014 4:45 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"jimmy bodo" wrote in message <lfd43r$opj$1@newscl01ah.mathworks.com>...
> In the code below
> for r=7:15
> for s=15:22
> total=1;
> while(i<=...)
> operations on total
> end
> i=i+1;
> end
> record(s)=total
> end
> final(r)=max(total)
> why is it that all the values in record and final are 1. shouldn't the value of total be updated?

Don't you want


INSIDE the while loop?

BTW, its a good idea to avoid using i (and j) as an index since it is used by MATLAB as the sqrt(-1)? Sooner or later this nuance is going to bite you.

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

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.