生成一个只有0,1的向量,向量元素之和为一定值。
Afficher commentaires plus anciens
比如生成一个1行20列的向量,所有元素之和为5,且两个1之间至少有一个0。我现在只能实现前两步,最后如何保证两个1之间至少有一个0?请高手帮忙解答
A=zeros(1,20);
idx=randperm(20);
A(idx(1:5))=1;A(idx(6:20))=0;
A
Réponses (0)
Catégories
En savoir plus sur 随机数生成 dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!