find count of elements in an array that meet certain condition

1 view (last 30 days)
suppose that i have an array ID= [ 5 9 5 9 0 ]
by using while loop i want to find number of elemnts that are greater than 5
and the number of elemnt less than 5
by using scilab instead of matlab

Answers (1)

Voss
Voss on 29 Apr 2022
Maybe someone on a scilab forum can say how to do it in scilab, but in MATLAB you can do the following:
ID = [5 9 5 9 0];
n_biggens = 0;
n_smallens = 0;
ii = 1;
n_ID = numel(ID);
while ii <= n_ID
if ID(ii) > 5
n_biggens = n_biggens+1;
elseif ID(ii) < 5
n_smallens = n_smallens+1;
end
ii = ii+1;
end
disp(n_biggens)
2
disp(n_smallens)
1

Community Treasure Hunt

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

Start Hunting!