matlab in the find () function usage

First, the function:

寻找非零元素的索引和值

Second, the correlation function syntax:

  1. ind = find(X)

  2. ind = find(X, k)

  3. ind = find(X, k, 'first')

  4. ind = find(X, k, 'last')

  5. [row,col] = find(X, ...)

  6. [row,col,v] = find(X, ...)

Third, explain:

  1. index= find(X)

    Find all non-zero elements in the matrix X, and the index values ​​of these linear elements (linear indices: columns) to return to the index of the vector.

    If X is a row vector, the index is a row vector; otherwise, index is a column vector.

    If X does not contain non-zero elements or a null matrix, the index is a null matrix.

  2. index = find(X, k) 或 3. index = find(X, k, 'first')

    Find the first K is not linear index value of 0. k must be a positive number, but it may be any type of a numerical value.

  3. index = find(X, k, 'last')

    k th non-zero elements found after the linear index.

  4. [row,col] = find(X, ...)

    Returns the index of non-zero elements of the matrix X rows and columns. This syntax is especially useful for sparse matrix.

    If X is an N (N> 2) dimensional matrix, col column comprises a linear index.

  5. [row,col,v] = find(X, ...)

    X returns a non-zero elements of a column or row vector v, and returns the row and column index value. If X is a logical representation, then v is a logic matrix. By evaluating the output vector v contains X represents a logical non-zero elements of the matrix obtained.

Clarification

I. Use a:

b=find(a),a是一个矩阵,查询非零元素的位置,如果X是一个行向量,则返回一个行向量;否则,返回一个列向量。如果X全是零元素或者是空数组,则返回一个空数组,例子如下所示,也可以用b=find(a>2),这句的意思是在a中找到比较2大的元素

a=[1 3;0 4]
b=find(a)

Export

a =

 1     3
 0     4

b =

 1
 3
 4

Explain Why do I get the value of b

a(1)

years =

 1


 a(2)

years =

 0

. II Usage II:

b = find (a, 2), two find a non-zero number that appears first, you are looking for is a matrix, the second parameter is the number of the

a=[1 3;0 4]
b=find(a,2)

Export

a =

 1     3
 0     4

b =

 1
 3

. III uses three:

c=find(a,2,'first')用法和二基本一样,如下

a=[1 3;0 4]
b=find(a,2,'first')

Export

a =

 1     3
 0     4

b =

 1
 3

. IV uses four:

c=find(a,2,'last') 这句的意思是从最后一个非零元素起,找2个不为零的元素,如下

a=[1 3;0 4]
b=find(a,2,'last')

Export

a =

 1     3
 0     4

b =

 3
 4   

V. five Usage:
[a1, a2] = Find (a), where a non-zero elements to identify the row and column matrix, and the presence of a1, a2 in

a=[1 3;0 4]
[a1,a2]=find(a)

Export

a =

 1     3
 0     4

a1 =

 1
 1
 2

a2 =

 1
 2
 2

. VI Usage six:

[a1,a2,v]=find(a),找出矩阵中非零元素所在行和列,并存在a1,a2中,并将结果放在v中,如下所示,这个得到的v是a中第几行第几列的**非零**元素

a=[1 3;0 4]
[a1,a2,val]=find(a)

Export

a =

 1     3
 0     4

a1 =

 1
 1
 2

a2 =

 1
 2
 2

val =

 1
 3
 4

. VII Usage seven:

[a1,a2,val]=find(a>2),返回一个单位列向量,这里不满足a>2,如下所示

a=[1 3;0 4]
[a1,a2,val]=find(a>2)

a =

 1     3
 0     4

a1 =

 1
 2

a2 =

 2
 2

val =

2 × 1 logical array

1
1

That val matrix row 1, column 2, line 2 and the second element 2 satisfy X> 2 is represented by 1 true.

Note the difference between the VI and VII

X = [4 2 0; -4 0 6; 0 0 2]
[a1,a2,val1]=find(X)
[a3,a4,val2]=find(X>2)

Export

X =

 4     2     0
-4     0     6
 0     0     2

a1 =

 1
 2
 1
 2
 3

a2 =

 1
 1
 2
 3
 3

VAL1 =

 4
-4
 2
 6
 2

a3 =

 1
 2

a4 =

 1
 3

val2 =

2 × 1 logical array

1
1

* Note that the value of val1.

Guess you like

Origin www.cnblogs.com/qw-blog/p/12343711.html