Get closest x value to y value from a cumulative histogram

5 次查看(过去 30 天)
Hi, This seems like a really simple question but I could not find any answers anywhere!
I have cumulative histogram of data and I want to find the x value that 95% of total values are above, and the x value that 5% of total values are above. This corresponds to 0.05 and 0.95 on the y axis. I have a very simple code simply using the histogram function.
histogram(i,100,'Normalization','cdf');
and I attached an image of the resulting histogram. I know I can use the data curser but I have 22 histograms I need to do it for so was hoping for a more automated way....
Help greatly appreciated!

采纳的回答

Are Mjaavatten
Are Mjaavatten 2018-2-27
If you have access to a toolbox with the prctile function (I don't), that will probably do the job.
Alternatively, try this:
h = histogram(i,100,'Normalization','cdf');
Values = h.Values;
BinCenters = (h.BinEdges(1:end-1)+h.BinEdges(2:end))/2;
% Eliminate any flat parts of the CDF:
FlatValues = find(diff([h.Values])==0)+1;
Values(FlatValues) = [];
BinCenters(FlatValues) = [];
percentiles = interp1(Values,BinCenters,[0.05,0.95])

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by