フィルターのクリア

I have a random number generator when the input selects the interval length and only runs it if it is between 50 and 200. I was wondering how do I round the output of random numbers so that they are only integers?(ex. 0,1,2,3,4,5,6,7,8,9 )

1 回表示 (過去 30 日間)
n= input('Enter Vector Size');
if n>=50 && n<=200
R= [0,1,2,3,4,5,6,7,8,9];
z = rand(n,1)*range(R)+min(R)
else
disp('Pick a Correct Vector Size')
n= input('Enter Vector Size');
R= [0,1,2,3,4,5,6,7,8,9];
z = rand(n,1)*range(R)+min(R)
end
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 10 月 4 日
編集済み: Walter Roberson 2018 年 10 月 4 日
Have you considered just using randi() ?
ps: what if someone enters a bad vector size twice in a row?
Stephen23
Stephen23 2018 年 10 月 4 日
"I was wondering how do I round the output of random numbers so that they are only integers?"
Two easy solutions:
  • Use randi, which returns integers.
  • Round the values using round, ceil, fix, or floor.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by