如何计算数组中的非零元素个数 matlab
2016-08-31 · 知道合伙人软件行家
关注
展开全部
ind = find(X)
ind = find(X, k)
ind = find(X, k, 'first')
ind = find(X, k, 'last')
[row,col] = find(X, ...)————用了这个
[row,col,v] = find(X, ...)
Description
ind = find(X) locates allnonzero elements of array X, and returns the ofthose elements in vector ind. If X isa row vector, then ind is a row vector; otherwise, ind isa column vector. If X contains no nonzero elementsor is an empty array, then ind is an empty array.
ind = find(X, k) or ind = find(X, k, 'first') returns at mostthe first k indices corresponding to the nonzeroentries of X. k must be a positiveinteger, but it can be of any numeric data type.
ind = find(X, k, 'last') returnsat most the last k indices corresponding to thenonzero entries of X.
[row,col] = find(X, ...) returnsthe 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, col containslinear indices for the columns. For example, for a 5-by-7-by-3 array X witha nonzero element at X(4,2,3), find returns4 in row and 16 in col. Thatis, (7 columns in page 1) + (7 columns in page 2) + (2 columns inpage 3) = 16.
[row,col,v] = find(X, ...) returnsa column or row vector v of the nonzero entriesin X, as well as row and column indices. If X isa logical expression, then v is a logical array.Output v contains the non-zero elements of thelogical array obtained by evaluating the expression X
ind = find(X, k)
ind = find(X, k, 'first')
ind = find(X, k, 'last')
[row,col] = find(X, ...)————用了这个
[row,col,v] = find(X, ...)
Description
ind = find(X) locates allnonzero elements of array X, and returns the ofthose elements in vector ind. If X isa row vector, then ind is a row vector; otherwise, ind isa column vector. If X contains no nonzero elementsor is an empty array, then ind is an empty array.
ind = find(X, k) or ind = find(X, k, 'first') returns at mostthe first k indices corresponding to the nonzeroentries of X. k must be a positiveinteger, but it can be of any numeric data type.
ind = find(X, k, 'last') returnsat most the last k indices corresponding to thenonzero entries of X.
[row,col] = find(X, ...) returnsthe 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, col containslinear indices for the columns. For example, for a 5-by-7-by-3 array X witha nonzero element at X(4,2,3), find returns4 in row and 16 in col. Thatis, (7 columns in page 1) + (7 columns in page 2) + (2 columns inpage 3) = 16.
[row,col,v] = find(X, ...) returnsa column or row vector v of the nonzero entriesin X, as well as row and column indices. If X isa logical expression, then v is a logical array.Output v contains the non-zero elements of thelogical array obtained by evaluating the expression X
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询