Get closest x value to y value from a cumulative histogram

조회 수: 3 (최근 30일)
Georgie
Georgie 2018년 2월 26일
댓글: kenneth meinert 2021년 2월 1일
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])
  댓글 수: 2
Georgie
Georgie 2018년 2월 28일
Thank you Are, that seems to work :)
kenneth meinert
kenneth meinert 2021년 2월 1일
Very nice peice of code. Works very well

댓글을 달려면 로그인하십시오.

추가 답변 (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