フィルターのクリア

Count number of rows in a matrix based on frequency of one element and value of another element

2 ビュー (過去 30 日間)
Hello. I'm quite rusty with Matlab and was wondering if anyone could help me with this. Let's say you have a 2000 x 2 matrix, where all the elements are integers. How can we count the number of rows that have the number 10 in the first column and any number greater than 5 in the second column?
I tried this, but didn't work:
numel(matrix(matrix(:,1) == 10) & matrix(matrix(:,2) > 5));
Thanks for your help!

採用された回答

Matt J
Matt J 2022 年 1 月 17 日
編集済み: Matt J 2022 年 1 月 17 日
nnz( matrix(:,1) == 10 & matrix(:,2) > 5 );
  2 件のコメント
Neuro
Neuro 2022 年 1 月 17 日
Thanks! Didn't know the nnz function! :)
Neuro
Neuro 2022 年 1 月 17 日
@Matt J Sorry, I just realised that this won't work as I need to count the zeroes as elements. Is there a way to do the same thing but counting the zeroes as ones? After all, I need to count the number of elements and zeroes are still elements.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by