is there's a way to automatically find peaks in an histogram?
120 views (last 30 days)
I have a script to analyze data from a detector (the data is not necessarily repeated). right now I have to find the peaks manually which is time-consuming!
is there's a way I can get the range of the peak base in the x-axis automatically? and is there's a way to neglect small peaks (let's say small in respect to the ratio from the max peak)?
here is an example of histogram I'm working with
Steven Lord on 29 May 2020
You can do this using the islocalmax function.
% Sample data
x = randn(1, 1e5);
h = histogram(x);
% Retrieve some properties from the histogram
V = h.Values;
E = h.BinEdges;
% Use islocalmax
L = islocalmax(V);
% Find the centers of the bins that islocalmax identified as peaks
left = E(L);
right = E([false L]);
center = (left + right)/2;
% Plot markers on those bins
plot(center, V(L), 'o')