How many positive entries in array

 Respuesta aceptada

Wayne King
Wayne King el 1 de Abr. de 2012
x = randn(1450,1);
indices = find(x>0);
length(indices)
or
count = length(nonzeros(x(x>0)));

Más respuestas (2)

hidayet beyhan
hidayet beyhan el 28 de Mzo. de 2020
Editada: hidayet beyhan el 28 de Mzo. de 2020

1 voto

Or you can use for an array:
x = randn(1450,1);
sum(x>0)
Varshitha Gouri
Varshitha Gouri el 7 de Jul. de 2026 a las 3:53
function count = positiveEntries(arr)
count = sum(arr > 0);
end

Categorías

Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 1 de Abr. de 2012

Respondida:

el 7 de Jul. de 2026 a las 3:53

Community Treasure Hunt

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

Start Hunting!

Translated by