代码之家  ›  专栏  ›  技术社区  ›  JohnIdol

Matlab中二进制值的均匀分布

  •  1
  • JohnIdol  · 技术社区  · 15 年前

    a = randint(1, sizeOfVector, [0 1]);
    

    这个 unifrnd function

    我能用这个箱子吗 统一 功能(如果是的话,我们将如何感谢!)或者有没有其他更方便的方法来获得这样一组向量?

    感谢您的帮助!

    :只是为了确定-以下是需求实际说明的内容:

    均匀分布在[0;1]

    附注2 :我正在为元胞自动机生成初始配置,这就是为什么我只能有二进制值[0;1].

    2 回复  |  直到 5 年前
        1
  •  2
  •   kennytm    15 年前

    要使用{0,1}中的元素生成1个随机向量,请执行以下操作:

    unidrnd(2,sizeOfVector,1)-1
    

    其他的变种是相似的。

        2
  •  0
  •   Jonas    15 年前

    如果你想得到均匀分布的0和1,你想使用 randi rand

    %# create a such that each row contains a vector
    
    a = randi(1,N,sizeOfVector); %# for uniformly distributed 0's and 1's
    
    %# if you want, say, 60% 1's and 40% 0's, use rand and threshold
    a = rand(N,sizeOfVector) > 0.4; %# maybe you need to call double(a) if you don't want logical output
    
    %# if you want a random number of 1's and 0's, use
    a = rand(N,sizeOfVector) > rand(1);