生成大小为N、浓度为1s(或,简单地说,浓度为0s)且从很低到很高的随机二进制向量的数量X的最佳方法是什么?
使用randint或unidrnd(如this question)将生成具有均匀分布的二进制向量,这不是我在本例中需要的。
感谢任何帮助!

最佳答案

Laserallan的方法是正确的。
对于一个包含10个元素和70%随机分布元素的向量,您可以编写

randVec = rand(10,1)<0.7;

编辑如果您想要长度为N的X向量,随着数量的增加,您可以编写
thresVec = linspace(0,1,X);  %# thresholds go from 0 (all 0) to 1 (all 1)
randVec = bsxfun(@lt,rand(N,X),threshVec); %# vectors are per column

注意,randVec是一个逻辑数组根据你想用它做什么,你可以把它转换成
randVec = double(randVec);

10-04 14:26