random selection of number among 2 numbers
8 ビュー (過去 30 日間)
古いコメントを表示
How do I randomly choose among 0 and 2 in matlab ? I have display the choosen number also.
Note: The choosen number should be either 0 or 2 not something in between.
0 件のコメント
回答 (1 件)
the cyclist
2021 年 6 月 9 日
編集済み: the cyclist
2021 年 6 月 9 日
Here are a couple ways:
2*randi([0 1])
2*round(rand())
2 件のコメント
Steven Lord
2021 年 6 月 9 日
A generalized version of Jan's answer:
Pool = (0:5).^2;
desiredSize = [1 7];
x = Pool(randi(numel(Pool), desiredSize))
参考
カテゴリ
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!