【问题标题】:generate a Gaussian dataset in MATLAB在 MATLAB 中生成高斯数据集
【发布时间】:2012-04-22 01:57:16
【问题描述】:

我想生成一个高斯数据集。该数据集包括从四个二维高斯类中随机抽取的总共 800 个样本,分布如下:

我怎样才能用 MATLAB 做到这一点。 我不是 MATLAB 专家!

【问题讨论】:

    标签: matlab dataset


    【解决方案1】:

    以下需要统计工具箱:

    % The means of the Gaussians
    mu    = [-3,0;0,0;3,0;6,0]; 
    
    % The covariance matrix
    sigma = [0.5,0.05;0.05,0.5]; 
    
    % The mixing proportions of the Gaussians
    p     = [0.25,0.25,0.25,0.25]; 
    
    % Make a Gaussian mixture distribution
    myMixtureDistribution = gmdistribution(mu,sigma,p); 
    
    % Draw random samples from the distribution
    myDataSample = myMixtureDistribution.random(800); 
    

    【讨论】:

    • 非常感谢,我收到以下错误:"??? 未定义变量 "d" 或类 "d.random"。"
    • 对不起,有一个错字。现已修复。
    【解决方案2】:

    randn()开头。

    【讨论】:

      【解决方案3】:

      我找到了如下答案: (谢谢大家)

      Sigma=[0.5 0.05; 0.05 0.5];
      z=mvnrnd([-3 0],Sigma,200);
      x=mvnrnd([0 0],Sigma,200);
      c=mvnrnd([3 0 ],Sigma,200);
      v=mvnrnd([6 0 ],Sigma,200);
      samples=[z; x; c; v];
      plot(samples(:,1),samples(:,2),'*');
      

      【讨论】:

        猜你喜欢
        • 2017-06-10
        • 1970-01-01
        • 1970-01-01
        • 2020-03-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-22
        • 1970-01-01
        相关资源
        最近更新 更多