help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

if statement to find values meeting certain conditions


From: dkimia1001
Subject: if statement to find values meeting certain conditions
Date: Thu, 29 Aug 2019 07:28:43 -0500 (CDT)

Hello,

I have a 200 by 18 array (called num1) and am trying to find some values
that meet certain criteria. 

What I am hoping to do is
 1. Starting from i=1, If num1(i, 15) is positive
 2. starting j=i,see if num1 (j, 18) is  positive. If negative, increase i
by 1 and repeat.
 3. If positive, increase j by 1 until num1 (j, 18) is negative . Let's call
this num (m, 18)
 4. Record values in other columns at rows j and m.
 5. The next scan starts from i=m until length(num1) is complete.

Below is what I have. Say num1 was positive at (2, 18) and turns negative at
(5, 18), instead of keeping only Rows 2 and 5 for the buydate, buyprice,
selldate, sellprice, the code records values at rows 2,3,4, 5 and moves on.
Please let me know where in the loop is not coded correctly. 

for i=i:length(num1)
  if num1(i, 15)>0  ##15 = 120 day derivative %
    j=i
    for j=j:length(num1)
      if num1 (j, 18)>0
        m=j+1;
        for m=m:length(num1)
          if num1(m,18)<0
            buydate(k,1)=num1(j,1); ## 1 = date
            buyprice(k,1)=num1(j,5); ## 5 = close price
            selldate(k,1)=num1(m,1); ## 1 = date
            sellprice(k,1)=num1(m,5); ## 5 = close price
            k=k+1;
            i=m+1;
            break;
          else
            m=m+1;
          endif
        endfor
        break;
      else 
        j=j+1;
      endif
    endfor
  endif
endfor



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]