Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Re: Checking Values in a For/If loop
Posted:
Apr 25, 2013 9:34 AM


"Josh Meyer" <jmeyer@mathworks.com> wrote in message news:klb9ls$ppj$1@newscl01ah.mathworks.com... > I can't tell what relation there is between your time(y) vector and the > other, so I can't really include it here. > > j=1; > for i=2:length(th) > if th(i)/th(i1)==.1
This is a Bad Idea; I would compare here with a tolerance or test that 10*th(i) == th(i1). See question 1 in the Math/Algorithms section of the newsgroup FAQ for why exact, bitforbit equality testing between noninteger valued floatingpoint numbers can result in answers you don't expect.
http://matlab.wikia.com/wiki/FAQ
Since you don't change th inside the loop, you can even get rid of the loop entirely.
th = [100 10 1 0.5 0.25] A = find(10*th(2:end) == th(1:end1))+1
*snip*
 Steve Lord slord@mathworks.com To contact Technical Support use the Contact Us link on http://www.mathworks.com



