find count of elements in an array that meet certain condition
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Voss
el 29 de Abr. de 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 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!