生成一个只有0,1的向量,向量元素之和为一定值。
Ältere Kommentare anzeigen
比如生成一个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
Antworten (0)
Kategorien
Mehr zu 随机数生成 finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!