matlab - how to retain monotonically increasing values of a one dimensional array -


lets have matrix,

x=[1,2,3,5,4,6,6,7,4,2,3,4,5,6,10,12,4,5,43,23,45,34,54,78]; 

now, want create new matrix want know indices , values, of elements value higher (not equal strictly larger than) previous ones.

so, array looking is,

y=[1,2,3,5,6,7,10,12,43,45,54,78]; 

because other numbers noise, , indices corresponding these values in vector x.

one more point avoid looping on array, actual data huge.

how using cummax compute running max:

cm = cummax(x); ind = [1,find(x(2:end) > cm(1:end-1))+1]; y = x(ind); 

adapting method divakar (until divakar posts if desired):

ind = find([true diff(cummax(x))>0]); y = x(ind); 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -