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

4 vues (au cours des 30 derniers jours)
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

Réponse acceptée

madhan ravi
madhan ravi le 9 Août 2019
W = sum(Y>0,2)
Z = max(W)

Plus de réponses (0)

Catégories

En savoir plus sur Data Types dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by