I have tried using Randi function,but it only gives me complete numbers.also tried rand but it doesn't give me to choose a specific range. Is there a function in matlab that would give me both complete and incomplete numbers in a specific range?I need to put this numbers in a matrix

 採用された回答

Matt J
Matt J 2020 年 5 月 8 日
編集済み: Matt J 2020 年 5 月 8 日

0 投票

To randomize uniformly over an interval [lower, upper], you would do,
out=rand(___)*(upper-lower)+lower

6 件のコメント

Stephanie khoury
Stephanie khoury 2020 年 5 月 8 日
Where I can put the range of numbers ?because when I tried to put it gives me an error
Image Analyst
Image Analyst 2020 年 5 月 8 日
Are you sure you looked in the help, because it does give you examples for how to specify a range.
Matt J
Matt J 2020 年 5 月 8 日
For example, to generate a 5x4 matrix of numbers uniformly distributed between 7 and 9,
A=rand(5,4)*(9-7)+7;
Stephanie khoury
Stephanie khoury 2020 年 5 月 8 日
I find that there option for me to choose a range in Randi function(that only gives complete numbers),but not in rand
Stephanie khoury
Stephanie khoury 2020 年 5 月 8 日
Thank you so much?
Matt J
Matt J 2020 年 5 月 8 日
that only gives complete numbers
No, you can use randi to generate any range of integers, not just the whole numbers. For example,
>> A=randi([-9,-7],5,4)
A =
-7 -7 -8 -7
-8 -7 -7 -7
-7 -9 -9 -8
-8 -7 -7 -9
-9 -8 -8 -7

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2020 年 5 月 8 日

0 投票

See the "Random Numbers Within Specified Interval" example on the documentation page for the rand function.
doc rand

カテゴリ

ヘルプ センター および File ExchangeRandom Number Generation についてさらに検索

質問済み:

2020 年 5 月 8 日

コメント済み:

2020 年 5 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by