简体   繁体   English

如何找到具有至少一个非零元素的列的索引?

[英]How to find the index of columns with at least one non-zero element?

Given a binary matrix in Matlab, I would like to find the index of the columns that have at least one non-zero element. 给定Matlab中的二进制矩阵,我想找到至少具有一个非零元素的列的索引。 How can I do this? 我怎样才能做到这一点?

B
     1     1     0     0     0
     0     0     0     1     0
     0     1     0     0     0
     0     0     0     0     0

You can use any and find to find the indices of the columns: 你可以使用anyfind找到列的索引:

indices = find(any(B,1))

Use any(B,1) to find the columns with at least one non-zero element, then use find to obtain the indices of these columns. 使用any(B,1)查找具有至少一个非零元素的列,然后使用find获得这些列的索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM