Get closest x value to y value from a cumulative histogram
조회 수: 3 (최근 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!
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!