for and if statements

3 ビュー (過去 30 日間)
Osita Onyejekwe
Osita Onyejekwe 2016 年 9 月 8 日
編集済み: s.p4m 2016 年 9 月 15 日
I need help generating a code that does the following
For and if Generate an array of 10 random numbers between 1 and 100. Then find out how many of the elements are between 1 and 25, how many between 25 and 75 and how many between 75 and 100.
  1 件のコメント
Thorsten
Thorsten 2016 年 9 月 8 日
This it homework. What have you tried to solve it?

サインインしてコメントする。

回答 (1 件)

s.p4m
s.p4m 2016 年 9 月 9 日
編集済み: s.p4m 2016 年 9 月 15 日
small = 0;
big = 0;
mid = 0;
test = random('Normal',1,100,1,10);
for k = 1:length(test)
if ( test(k) < 25 )
small = small + 1;
elseif ( test(k) > 75 )
big = big + 1;
else
mid = mid + 1;
end
end

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by