In MATLAB (cumulative distribution function), how can I find the corresponding data point (Y) for any chosen cumulative probability?

StackOverflow https://stackoverflow.com/questions/16804056

Question

In a CDF (using MATLAB) how can I find the corresponding data value (X) for any chosen cumulative distribution (Y)? Please refer to the pasted code (I would post an image but I need a "10 reputation"). Instead of "eye-balling" the plot, how can I find the data point (X) that corresponds to the cumulative probability value of 0.2 or even 0.5, etc.? Please advise. Thank you.

X = randn(1,500);
u = mean(X);
s = std(X);
pd = makedist('Normal','mu',u,'sigma',s);
x = min(X):.1:max(X);
cdf_normal = cdf(pd,x);
plot(x,cdf_normal,'LineWidth',4)
Was it helpful?

Solution

I don't know what is in makedist, but Matlab has a powerful tool called find which will seek out what you need.

In your case, if I had to guess, you can do

x(find(cdf_normal >= 0.2,1))

to get your desired data point x.

Basically it searches cdf_normal for the first occurrence of the correct statement, returns the index, then displays the value if x which corresponds to that index.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top