How to compute area under histogram?
10 ビュー (過去 30 日間)
古いコメントを表示
Dear all, I wanted to compute the area under histogram for certain percent of area. I have a code of creating histogram plot is like this:
hisdataplot = subplot('position', [0.62 0.10 0.15 0.70]);
mindata = min(data);
maxdata = max(data);
nbins = 10;
binrange = linspace(mindata, maxdata, nbins);
ll = histc(data,binrange);
ll2 = zeros(2*length(hist(data)),2);
for kkr=1:length(ll)
ll2(2*kkr-1,:) = [kkr-1 ll(kkr)/360];
ll2(2*kkr,:) = [kkr ll(kkr)/360];
end
ll3 = [0 0; ll2; kkr 0];
plot(ll3(:,1),ll3(:,2)/max(ll3(:,2)),'-k', 'LineWidth',1.0);
set(gca,'Xtick',[0 length(ll)]);
set(gca,'Xlim',[0 length(ll)]);
set(gca,'Ytick',[0 1.2]);
set(gca,'TickLength',[0 0]);
set(gca,'Ylim',[-0.05 1.2]);
Say I want to compute the 80 percent of area and know where it occurs along x-axis. Also, I want to plot this line in the histogram.Is there any command? Kindly let me know. Thanks in advance.
Mahesh
1 件のコメント
Siddharth Sundar
2014 年 10 月 13 日
There is no command that does this directly. Is there a reason that you are computing the area under the histogram? The histogram area varies with bin size, bin width etc. so if you are looking to extract some information, you might want to keep this in mind.
Given the x and y data you give to the plot command (ll3*(:,1) and ll3(:,2)/max(ll3(:,2))), you can compute the area under the whole curve using the trapz command.
To find the exact X coordinate that encompasses a certain area, you need to find the cumulative sum and iterate over it to match the desired percentage area.
採用された回答
Mohammad Abouali
2014 年 10 月 13 日
You can do that and manually compute the 80 percentile value or you can use the matlab function
Y = prctile(X,p)
where X is your data and p is the percentile that you want, so 80.
0 件のコメント
その他の回答 (1 件)
Image Analyst
2014 年 10 月 13 日
Not sure what toolbox prctile() is in, but I don't have it. You can use this alternative:
cdf = cumsum(ll); % Sum histogram counts to get cumulative distribution function.
cdf = cdf / cdf(end); % Normalize.
% Get data value where 80% is.
dataGT80 = find(cdf>= 0.8, 1, 'first');
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!