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

4 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

madhan ravi
madhan ravi am 9 Aug. 2019
W = sum(Y>0,2)
Z = max(W)

Weitere Antworten (0)

Kategorien

Mehr zu Data Types finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by