find count of elements in an array that meet certain condition
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposte (1)
Voss
il 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)
disp(n_smallens)
0 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!