フィルターのクリア

Count number of rows that meet criteria based on elements in other rows

26 ビュー (過去 30 日間)
Neuro
Neuro 2022 年 3 月 31 日
回答済み: Voss 2022 年 3 月 31 日
Hello. How can one count the number of rows based on the elements in the columns? For example, if we have the following matrix:
3 0 0 2
5 0 0 2
2 0 1 2
2 0 1 2
1 1 1 3
4 1 0 2
3 1 1 2
1 1 1 3
5 1 0 1
4 1 1 1
How can we count the number of rows that have number 2 in the first column and number 1 in the third column? I guess one should use 'length' right? Thanks!

回答 (1 件)

Voss
Voss 2022 年 3 月 31 日
nnz(A(:,1) == 2 & A(:,3) == 1)
% 1st column is 2 & 3rd column is 1
where A is your matrix

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by