How to generate a random decimal number between -1 and 1?
8 ビュー (過去 30 日間)
古いコメントを表示
I'm trying to use rand below but it is giving me [ ].
rand([-1 1]);
1 件のコメント
Ameer Hamza
2020 年 10 月 29 日
編集済み: Ameer Hamza
2020 年 10 月 29 日
The answer here: https://www.mathworks.com/matlabcentral/answers/630328-how-to-generate-a-random-decimal-number-between-1-0-and-1-52 will also work for this question. Just use
range = [-1 1]
採用された回答
その他の回答 (1 件)
Walter Roberson
2020 年 10 月 29 日
rand*2-1
Note this will not generate exactly -1 or exactly 1
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Random Number Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!