mfind()

Read(1904) Label: vector, matrix, non-zero,

Description:

Search for positions of non-zero members in a vector or matrix.

Syntax:

mfind(A, n)

Note:

The external library function (See External Library Guide) searches for positions of the first n non-zero members in vector or matrix A.

 

It gets the position of the first non-zero member when parameter n is absent. If the total number of non-zero members is fewer than n, it returns positions of all non-zero, non-null members.

 

Search column by column when A is a matrix and return sequence numbers of positions of non-zero members in the matrix.

Parameter:

A

A vector or a matrix.

n

A positive integer.

Return value:

Sequence

Example:

 

A

 

1

[0,,5,2,0,2,1,0]

 

2

=mfind(A1)

Return position of the first non-zero member as parameter n is absent.

3

=mfind(A1,3)

Return positions of the first non-zero members.

4

=mfind(A1,10)

Return positions of all non-zero members since the number of them in matrix A1 is fewer than n (here is 10).

5

[[1,0,2],[0,0,2],[0,4,7]]

 

6

=mfind(A5,3)

As parameter A is a matrix, search for the first three non-zero members by column and the result are “1”,“4”,”2”, whose sequence numbers of positions are 1,6,7.