Random number vector with only two values
6 次查看(过去 30 天)
显示 更早的评论
采纳的回答
Stephen23
2024-9-23
编辑:Stephen23
2024-9-23
Indexing is a basic MATLAB superpower. You can easily use indexing to select from a vector of any values:
V = [0,pi];
W = V(randi(numel(V),1,10))
Multiplication also works for this special case with only two values, one of which is zero:
W = pi * randi([0,1],1,10)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!