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 CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by