Do we have any Fucntion which can generate +1 and -1 randomly????
1 回表示 (過去 30 日間)
古いコメントを表示
I am using the following thing to generate it...
a=rand(1,10);
b=round(a);
b( b==0 )=-1;
So is there any other best way to genrate +1 and -1 randomly
0 件のコメント
採用された回答
Mohammad Abouali
2014 年 10 月 26 日
編集済み: Mohammad Abouali
2014 年 10 月 26 日
I don't think there is any function doing that.
Here is another approach:
sign(rand(1,10)-0.5)
or
(-1).^(round(rand(1,10)))
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!