find函数

来源:互联网 发布:人脸变漫画软件 编辑:程序博客网 时间:2024/05/21 08:42

find 

Find indices and values of nonzero elements

查找索引号和非零元素的值

Syntax

语法

indices = find(X)

[i,j] = find(X)

[i,j,v] = find(X)

[...] = find(X, k)

find(X, k, 'first')

[...] = find(X, k, 'last')

Description

描述

indices = find(X) returns the linear indices corresponding to the nonzero entries of the array X. If none are found, find returns an empty matrix. In general, find(X) regards X as X(:), which is the long column vector formed by concatenating the columns of X.

Indices=find(X) 返回线性索引号与阵列X的非零元素相符合的。如果没有找到,find返回一个空矩阵。一般的,find(X)X看作X(:),其是通过串联X的行构成长行向量。

[i,j] = find(X) returns the row and column indices of the nonzero entries in the matrix X. This syntax is especially useful when working with sparse matrices. If X is an N-dimensional array with N > 2, j contains linear indices for the dimensions of X other than the first.

[i,j]=find(X) 返回矩阵X中的非零元素的行号和列号。当操作的是稀疏矩阵的时候这个语法特别适用。如果X是一个N维阵列并且N>2j包含线性指数X阵列的大小除了第一个。

[i,j,v] = find(X) returns a column vector v of the nonzero entries in X, as well as row and column indices.

[i,j,v]=find(X) 返回一个X中的非零元素的行向量v,和行和列的索引号一样。

[...] = find(X, k) or [...] = find(X, k, 'first') returns at most the first k indices corresponding to the nonzero entries of X. k must be a positive integer, but it can be of any numeric data type.

[...]=find(X,k)[...]=find(X,k,'first') 返回至多第一个k索引号与X的非零元素相符合的。k必须是一个确切的整数,但是它能够做任何数值数据类型的计算。

[...] = find(X, k, 'last') returns at most the last k indices corresponding to the nonzero entries of X.

[...]=find(X,k,'last')返回至多最后k索引号与X的非零元素相符合的。

Examples

例如

X = [1 0 4 -3 0 0 0 8 6];

indices = find(X)

returns linear indices for the nonzero entries of X.

返回X的非零元素的线性索引号

indices =

     1     3     4     8     9

You can use a logical expression to define X. For example,

你能够使用一个逻辑表达式来定义X。例如,

find(X > 2)

returns linear indices corresponding to the entries of X that are greater than 2.

返回与X元素中相符合的线性索引号,其在X元素中所指向的数值均大于2

ans =

     3     8     9

The following commands

下面的命令行

X = [3 2 0; -5 0 7; 0 0 1];

[i,j,v] = find(X) 

Return

返回

i =

     1

     2

     1

     2

     3

a vector of row indices of the nonzero entries of X,

一个列的向量,X的非零元素的索引号

j =

     1

     1

     2

     3

     3

a vector of column indices of the nonzero entries of X, and

一个行的向量,X的非零元素的索引号,并且

v =

     3

    -5

     2

     7

     1

a vector containing the nonzero entries of X.

一个向量包含X的非零元素。

Some operations on a vector

一些在一个向量上操作

x = [11  0  33  0  55]';

find(x)

ans =

     1

     3

     5

find(x == 0)

ans =

     2

     4

find(0 < x & x < 10*pi)

ans =

     1

For the matrix

矩阵

M = magic(3)

M =

     8     1     6

     3     5     7

     4     9     2

find(M > 3, 4)

returns the indices of the first four entries of M that are greater than 3.

返回M的元素大于3的所有数值中的前4个值的索引号。

ans =

     1

     3

     5

     6