Hi, How can I compare whether an element of a vector is greater, or less than the previous one and if equal check one before the previous and so on.
A=[2; 3; 4; 2; 2; 3; 7; 3; 3] size 10×1 could be 10e5x1
Out=[1; 1; -1; -1; 1; 1; -1; -1] size 9×1
3 > 2 then 1 in out ; 4>3 the same; 2<4 then -1; 2=2 then go back to a number that is not 2(it may not be always the direct preceding number if there is a sequence of 2s for like 10^n rows) , in this case 4 is the first number so use 4 , 2<4 then -1 and so on
Best Answer