从MATLAB中的经验累积分布函数生成随机数(Generate random numbers from empirical cumulative distribution function in MA

编程入门 行业动态 更新时间:2024-10-27 01:30:45
从MATLAB中的经验累积分布函数生成随机数(Generate random numbers from empirical cumulative distribution function in MATLAB)

我在MATLAB中通过生成经验累积分布函数

x = [1, 1.2, ..., 1] [myECDF, xi] = ecdf(x);

现在我想用这个ECDF作为绘制一组随机数的基础。 例如,我想做这样的事情:

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

这在MATLAB中可行吗?

I generated an empirical cumulative distribution function in MATLAB via

x = [1, 1.2, ..., 1] [myECDF, xi] = ecdf(x);

Now I would like to use this ECDF as a basis to draw a set of random numbers from. For example, I would like to do something like this:

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

Is this possible in MATLAB?

最满意答案

您可以使用反向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

You can use the inverse CDF method. Generate uniformly distributed random variables between 0 and 1 and treat them as CDF outputs. Then use your empirical distribution to find the corresponding values.

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

更多推荐

本文发布于:2023-08-03 00:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1382514.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:随机数   函数   经验   Generate   MATLAB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!