Simple column vector - random number question.

1 回表示 (過去 30 日間)
Danny C
Danny C 2016 年 9 月 6 日
コメント済み: Danny C 2016 年 9 月 6 日
Create a column vector of length "num" that consists of random numbers that are uniformly distributed between 2 and 9. (D)
D = randi([2 9],num,1);
D = 2+ 7.*rand(num,1) ;
Why aren't those two true? And what would be the right one?

採用された回答

James Tursa
James Tursa 2016 年 9 月 6 日
編集済み: James Tursa 2016 年 9 月 6 日
You need to apply the floor() function to rand to get integer results, and your range multiplier isn't quite correct for the range you want. E.g.,
D = 2 + floor(8.*rand(num,1)); % <-- Changed 7 to 8 and added floor() function
  1 件のコメント
Danny C
Danny C 2016 年 9 月 6 日
Working! Thank you :)

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

その他の回答 (0 件)

カテゴリ

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