【问题标题】:Generate random numbers from empirical cumulative distribution function in MATLAB从 MATLAB 中的经验累积分布函数生成随机数
【发布时间】:2018-03-08 16:46:30
【问题描述】:

我在 MATLAB 中通过

生成了一个经验累积分布函数
x = [1, 1.2, ..., 1]
[myECDF, xi] = ecdf(x);

现在我想以此 ECDF 为基础从中抽取一组随机数。例如,我想做这样的事情:

y = random(myECDF, 10);  // drawing 10 random numbers from ECDF

这在 MATLAB 中可行吗?

【问题讨论】:

    标签: matlab


    【解决方案1】:

    您可以使用逆 CDF 方法。生成介于 0 和 1 之间的均匀分布的随机变量,并将它们视为 CDF 输出。然后使用您的经验分布找到相应的值。

    function my_x = my_random(myECDF, xi, N)
        % Generate N uniformly distributed samples between 0 and 1.
        u = rand(N,1);
        % Map these to the points on the empirical CDF.
        my_x = interp1(myECDF, xi, u, 'linear');
    end
    

    【讨论】:

    • 谢谢,正是我需要的!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    • 1970-01-01
    • 2011-09-11
    • 2016-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多