How many positive entries in array

41 Ansichten (letzte 30 Tage)
Mate 2u
Mate 2u am 1 Apr. 2012
Bearbeitet: hidayet beyhan am 28 Mär. 2020
I have a 1450x1 array. I want to count how many positive entries in array?

Akzeptierte Antwort

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

Weitere Antworten (1)

hidayet beyhan
hidayet beyhan am 28 Mär. 2020
Bearbeitet: hidayet beyhan am 28 Mär. 2020
Or you can use for an array:
x = randn(1450,1);
sum(x>0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by