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: storing a vector within a while look and plotting it
Replies: 4   Last Post: Sep 18, 2012 5:10 PM

Advanced Search

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

Posts: 10
Registered: 9/17/12
Re: storing a vector within a while look and plotting it
Posted: Sep 18, 2012 5:10 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"someone" wrote in message <k3a3mo$aq0$1@newscl01ah.mathworks.com>...
> "Matt" wrote in message <k389d4$l74$1@newscl01ah.mathworks.com>...
> > "someone" wrote in message <k37o5r$gja$1@newscl01ah.mathworks.com>...
> > > "Matt" wrote in message <k37n44$clv$1@newscl01ah.mathworks.com>...
> > > > I have a while loop that keeps iterating until a certain value is within a certain error bound. The while loop runs 8 times and keeps overriding an old value with the new one as the result gets closer to the error bound that I have specified. What I'm trying to do is store every value that the function spits out to a vector so I can plot it.
> > > > I think that should make sense and I would really appreciate any help.

> > >
> > >
> > > % Something like this maybe:
> > >
> > > idx = 0;
> > > while result > errorBound
> > > % insert your code here that computes result
> > > idx = idx + 1;
> > > errorVector(idx) = result;
> > > end
> > >
> > > plot (errorVector)
> > >
> > > % Note: If possible you should preallocate errorVector.

> >
> > I have this code.
> > while(1)
> > function goes here that produces 3 values for sol
> >
> > idx=1;
> > vect(idx)=sol
> > idx=idx+1;
> >
> > if sol~=0
> > my error function goes here
> > end
> >
> > if err_ap <= .05 | iter >= maxit, break, end
> > end
> >
> > I ran this code in command window and typed in in vect and it only spits out one value.

>
> Move the "idx=1" statement outside (before) the while loop.


wow i can't believe I didn't realize this myself. thanks for help!



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.