/* find in Matlab */ /* Notice: Its result is always a column vector. */ new; cls; x={3,0,0,-1,2}; print find(x); x={8 1 6, 3 5 7, 4 9 2}; print findfirstk(x.>3,4); print findlastk(x.>3,4); proc find(x); local i,y; x=vec(x'); i=seqa(1,1,rows(x)); y=(x./=0).*i; y=delif(y,y.==0); retp(y); endp; proc findfirstk(x,k); local i,y; x=vec(x'); i=seqa(1,1,rows(x)); y=(x./=0).*i; y=delif(y,y.==0); y=y[1:k]; retp(y); endp; proc findlastk(x,k); local i,y; x=vec(x'); i=seqa(1,1,rows(x)); y=(x./=0).*i; y=delif(y,y.==0); y=y[rows(y)-k+1:rows(y)]; retp(y); endp;