find count of elements in an array that meet certain condition

1 回表示 (過去 30 日間)
Islam Farag
Islam Farag 2022 年 4 月 29 日
回答済み: Voss 2022 年 4 月 29 日
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

回答 (1 件)

Voss
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)
2
disp(n_smallens)
1

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by