Function to transform empirical distribution to a uniform distribution in Matlab?

坚强是说给别人听的谎言 提交于 2019-12-12 06:01:02

问题


I know the procedure of transforming one distribution to another by the use of CDF. However, I would like to know if there is existing function in Matlab which can perform this task?

My another related question is that I computed CDF of my empirical using ecdf() function in Matlab for a distribution with 10,000 values. However, the output that I get from it contains only 9967 values. How can I get total 10,000 values for my CDF? Thanks.


回答1:


As you say, all you need is the CDF. The CDF of a normal distribution can be expressed in terms of the erf Matlab function.

Untested example:

C = @(x)(0.5 * (1 + erf(x/sqrt(2))));

x = randn(1,1000);  % Zero-mean, unit variance
y = C(x);           % Approximately uniform



回答2:


for t=1:nT 
    [f_CDFTemp,x_CDFTemp]=ecdf(uncon_noise_columndata_all_nModels_diff_t(:,1,t)); % compute CDF of empirical distribution
    f_CDF(1:length(f_CDFTemp),t) = f_CDFTemp; % store the CDF of different distributions with unequal size in a new variable
    x_CDF(1:length(x_CDFTemp),t) = x_CDFTemp;
    b_unifdist=4*t;
    [Noise.N, Noise.X]=hist((a_unifdist+(b_unifdist-a_unifdist).*f_CDF(:,t)),100); % generate the uniform distribution by using the CDF of empirical distribution as the CDF of the uniform distribution
    generatedNoise(:,:,t)=emprand(Noise.X,nRows,nCol); % sample some random numbers from the uniform distribution generated above by using 'emrand' function
end



回答3:


This is not exactly what you are looking for, but it shows how to do the opposite. Reversing it should not be that bad.



来源:https://stackoverflow.com/questions/11317744/function-to-transform-empirical-distribution-to-a-uniform-distribution-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!