How to Generate a Random # Between -1 and 1?
5 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I have a simple question. I want to produce a random number between -1 and 1 as the title states. I tried doing this already:
randnum = rand(1)
But this will always be positive because it will generate between 0 and 1. So I tried this:
randnum = rand([-1,1])
But I receive an empty, double column vector.
0 件のコメント
採用された回答
Image Analyst
2018 年 11 月 26 日
Did you look in the help where is told you how to get a number in the range from a to b?
r = 2 * rand - 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!