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!