[英]How to find the indeces of the columns with at least k non-zero element on it?
I have a matrix A as follows: 我有一个矩阵A,如下所示:
A =
1 2 0 0 4
0 0 0 1 3
0 0 1 1 1
I would like to find the indecies of column A where each column has more than k-nonero elements. 我想找到A列的指标,其中每一列都包含多个k-nonero元素。 I used: 我用了:
find(all(A~=0));
but it returns the index of the columns where there exist at least one non-zero element. 但是它返回至少存在一个非零元素的列的索引。
It might help you if you take it step by step. 如果逐步进行,可能会对您有所帮助。
First, find the number of nonzero elements in each column: 首先,找到每列中非零元素的数量:
nNonZero = sum(A~=0)
Then find the columns that are more than k 然后找到大于k的列
find(nNonZero>k)
Instead of checking where all the values in a row are non-zero, rather count how many are and then apply your threshold: 与其检查行中所有值都不为零的位置,不如计算多少个值,然后应用阈值:
k = 3
find(sum(A~=0,2)>=k)
returns: 收益:
ans =
1
3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.