简体   繁体   English

如何在Matlab中找到> 0的矩阵元素?

[英]How to find the elements of a matrix > 0 in Matlab?

我很好奇-是否有单个Matlab命令返回Matrix中大于0的元素?

The following code returns all positive elements of matrix A : 以下代码返回矩阵A所有正元素:

A(find(A > 0))

or in short form as proposed by Gunther Struyf: 或Gunther Struyf建议的简写形式:

A(A > 0)

The find function will return the indices of elements that are not zero. find函数将返回不为零的元素的索引。

ind = find(A > 0);

is what you're looking for... 是您要寻找的...

或为此目的专门设计的命令:“ nonzeros”

nz_A = nonzeros(A);

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

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