大于阈值的值的数量

MKS*_*MKS 8 indexing matlab

我有一个矩阵A.现在我想找到大于5的元素数量及其相应的索引.如何在不使用for循环的情况下在matlab中解决这个问题?

例如,如果A = [1 4 6 8 9 5 6 8 9]':

  • 元素数量> 5:6
  • 指数: [3 4 5 7 8 9]

Jon*_*nas 14

你用find:

index = find(A>5);
numberOfElements = length(index);
Run Code Online (Sandbox Code Playgroud)