Non-zero member search

 

mfind(A,n), search for positions of non-zero members in A.


A
1 [0,6,0,23,56,1,0]
2 =mfind(A1,3)
3 =mfind(A1)
4 =mfind(A1,20)

A1 Input a vector with zero members

A2 Find the position of the first 3 non-zero elements of A1. The first 3 non-zero elements in A1 are 6,23,56, corresponding positions are 2,4,5, so return the position sequence is [2,4,5]

A3 Finds the position of the first non-zero element when parametern is omitted, returning 2

A4 If n is greater than the number of elements, return the position sequence of all non-zero elements [2,4,5,6]