find count of elements in an array that meet certain condition
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Voss
2022-4-29
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!