I have a 1450x1 array. I want to count how many positive entries in array?

 채택된 답변

Wayne King
Wayne King 2012년 4월 1일

3 개 추천

x = randn(1450,1);
indices = find(x>0);
length(indices)
or
count = length(nonzeros(x(x>0)));

추가 답변 (2개)

hidayet beyhan
hidayet beyhan 2020년 3월 28일
편집: hidayet beyhan 2020년 3월 28일

1 개 추천

Or you can use for an array:
x = randn(1450,1);
sum(x>0)
Varshitha Gouri
Varshitha Gouri 2026년 7월 7일 3:53

0 개 추천

function count = positiveEntries(arr)
count = sum(arr > 0);
end

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

질문:

2012년 4월 1일

답변:

2026년 7월 7일 3:53

Community Treasure Hunt

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

Start Hunting!

Translated by