How to find the maximum peak of histogram probability and error from true value?
26 views (last 30 days)
Show older comments
Hello, I would only like to find the maximum peak of the probability, not more than one, plus determine its errors from the true value = 1 (red line). This is what I've done and it returns more than one value for the the peak. Thanks in advance!
histplot = histogram(data);
hold on
line([1, 1],ylim,'Linewidth',2, 'Color', 'r');
kernel = ksdensity(data);
peak = findpeaks(kernel);
disp(['The peak of the histogram is at: ' num2str(peak)]);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/203260/image.png)
4 Comments
Adam Danz
on 8 Feb 2019
It's tough to make a call without seeing the distribution. Would max() work?
[maxValue, maxIndex] = max(kernel)
Answers (1)
Steven Lord
on 8 Feb 2019
x = randn(1, 1e5);
h = histogram(x);
[maxcount, whichbin] = max(h.Values);
title("Maximum of " + maxcount + " occurs in bin " + whichbin + ...
" between " + h.BinEdges(whichbin) + " and " + h.BinEdges(whichbin+1));
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!