如何计算数组中的非零元素个数 matlab

 我来答
EvenHHZ
2016-08-31 · 知道合伙人软件行家
EvenHHZ
知道合伙人软件行家
采纳数:13691 获赞数:18845
个人出版图书:《玩转Python网络爬虫》、《玩转Django2.0》

向TA提问 私信TA
展开全部
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
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式