How to create a set of random numbers
7 次查看(过去 30 天)
显示 更早的评论
采纳的回答
Stephen23
2017-3-30
编辑:Stephen23
2017-3-30
You could use randperm to randomly arrange a vector of exactly those numbers:
>> vec = [repmat(1,21,1);repmat(2,38,1);repmat(3,31,1)]; % or use REPELEM
>> vec = vec(randperm(numel(vec)));
And checking that it fulfills your requirements:
>> numel(vec)
ans = 90
>> nnz(vec==1)
ans = 21
>> nnz(vec==2)
ans = 38
>> nnz(vec==3)
ans = 31
更多回答(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!