Path: news.mathworks.com!not-for-mail From: "Josh Meyer" <jmeyer@mathworks.com> Newsgroups: comp.soft-sys.matlab Subject: Re: Checking Values in a For/If loop Date: Thu, 25 Apr 2013 09:04:57 -0400 Organization: MathWorks Lines: 44 Message-ID: <klb9ls$ppj$1@newscl01ah.mathworks.com> References: <kl9s92$ptr$1@newscl01ah.mathworks.com> Reply-To: "Josh Meyer" <jmeyer@mathworks.com> NNTP-Posting-Host: ah-jmeyer.dhcp.mathworks.com Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="UTF-8"; reply-type=response Content-Transfer-Encoding: 7bit X-Trace: newscl01ah.mathworks.com 1366895100 26419 172.28.8.99 (25 Apr 2013 13:05:00 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Thu, 25 Apr 2013 13:05:00 +0000 (UTC) In-Reply-To: <kl9s92$ptr$1@newscl01ah.mathworks.com> X-Priority: 3 X-MSMail-Priority: Normal Importance: Normal X-Newsreader: Microsoft Windows Live Mail 14.0.8089.726 X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8089.726 Xref: news.mathworks.com comp.soft-sys.matlab:794328 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(i-1)==.1 A(j) = i; j = j+1; end end for ex, with th = [100 10 1 0.5 0.25]; this loop returns A = 2 3 You may wish to preallocate A as a vector of zeros if you're dealing with a large number of checks. "Mary " <22luongo@cardinalmail.cua.edu> wrote in message news:kl9s92$ptr$1@newscl01ah.mathworks.com... > This is the jist of what I want to set up, I'm just fuzzy on how to go > about it: > > th(k)= vector of values [ko k1 k2 k3...] > time(y) = time vector of values [t1 t2 t3] > the vectors have equal lengths and are going to be plotted together > > for ( to cycle through all values of th(k)); > if k1/ko == .1 > then stop code and show the value of k and y that was true for > else > continue cycling through each th(k) vector value until that becomes true > (example next cycle would check k2/k1 ==.1 etc) > > ko = initial value > k1 = value right next to it > > I havent worked with vectors in forever and I would appreciate any help! > > Thanks!