https://zhuanlan.zhihu.com/p/22484964 链接是知乎上总结的Octave/Matlab教程-Coursera-斯坦福-机器学习
下面是find的用法
'find' is a built-in function from the file libinterp/corefcn/find.cc
-- IDX = find (X)
-- IDX = find (X, N)
-- IDX = find (X, N, DIRECTION)
-- [i, j] = find (...)
-- [i, j, v] = find (...)
Return a vector of indices of nonzero elements of a matrix, as a row if X is a row vector or as a column otherwise.
返回一个矩阵的非零元素的索引向量,如果X是一个行向量则返回的IDX是一个行向量,如果X是列向量,,则返回列向量
比如行向量 X=[0,1,2,3],find(X)返回[2 3 4];列向量X=[0;1;2;3],find(X)返回[2;3; 4].。X=[0,1;2,3]两行两列,find(X)返回[2;3; 4]
find (eye (2))
=> [ 1; 4 ]
-- IDX = find (X, N)
If two inputs are given, N indicates the maximum number of elements to find from the beginning of the matrix or vector.
如果有两个输入,N表示从矩阵或者向量的开始位置返回非零元素索引值的最大数量,比如说X=[0;1;2;3],非零索引是2,3,4,所以find(X,2)表示返回数最多两个,就是[2,3]
如果N=3或者3以上,结果都为[2;3;4];
-- IDX = find (X, N, DIRECTION)
If three inputs are given, DIRECTION should be one of "first" or "last", requesting only the first or last N indices, respectively.
However, the indices are always returned in ascending order.
如果有三个输入,direction为"first"或者"last",first表明返回前面N个索引值,last表明返回最后N个索引值,比如X=[0;1;2;3],find(X,2,"last")为[3;4]
If two outputs are requested, 'find' returns the row and column indices of nonzero elements of a matrix. For example:
如果有两个输出,find返回一个矩阵的行和列索引值,i为行索引,j为列索引。
[i, j] = find (2 * eye (2))
=> i = [ 1; 2 ]
=> j = [ 1; 2 ]
If three outputs are requested, 'find' also returns a vector containing the nonzero values. For example:
如果有两个输出,find返回一个矩阵的行和列索引值,i为行索引,j为列索引,v为矩阵内的所有非零元素。
[i, j, v] = find (3 * eye (2))
=> i = [ 1; 2 ]
=> j = [ 1; 2 ]
=> v = [ 3; 3 ]
Note that this function is particularly useful for sparse matrices, as it extracts the nonzero elements as vectors, which can then be
used to create the original matrix. For example:
sz = size (a);
[i, j, v] = find (a);
b = sparse (i, j, v, sz(1), sz(2));
See also: nonzeros.
Additional help for built-in functions and operators is available in the online version of the manual. Use the command 'doc <topic>' to search the manual index.
Help and information about Octave is also available on the WWW at http://www.octave.org and via the help@octave.org mailing list.