count numbers greater than zero, and determine among them has the highest number of count

4 ビュー (過去 30 日間)
I have matric Y, and I want to count how many numbers (i.e. more > 0) in row, and determine the highest value
% Raw data
Y=
[1 2 0 0 0 0 0 0 0;
1 3 2 0 0 0 0 0 0;
1 4 3 2 0 0 0 0 0;
1 3 0 0 0 0 0 0 0;];
% count total numbers in each row (more > 0, i.e. dont count Zeros)
W =
[2;
3;
4;
2;];
% tell me what's the highest number in W
Z =
4

採用された回答

madhan ravi
madhan ravi 2019 年 8 月 9 日
W = sum(Y>0,2)
Z = max(W)

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by