local maxima \ minima
No License
This is a very simple function to find the local maximum in any dimensional array. As simple as it is it still gives nice results.
I use the imdilate() function as a maximum operation and then compare the data to the result.
The function receives three parameters:
the data, a vector defining the minimum distance between peaks in each of the data dimensions. and a flag either to exclude equal points or not.
use examples:
a = cumsum(randn(1000,1));
peaks = localMaximum(a,[100]);
figure; plot(a); hold on; plot(peaks,a(peaks),'ro');
[x y] = meshgrid(-6:0.1:6,-6:0.1:6);
a = sinc(x).*sinc(y);
lMaxInd = localmaximum(a,[20 20]);
lMinInd = localMaximum(-a,[20 20]);
figure; mesh(x,y,a); hold on;
plot3(x(lMaxInd),y(lMaxInd),a(lMaxInd),'k*','markersize',10,'linewidth',1.5);
plot3(x(lMinInd),y(lMinInd),a(lMinInd),'g*','markersize',10','linewidth',1.5);
legend('sinc(x)sinc(y)','peaks','valleys','location','best')
P.S
- It is recommended to run (if possible) a LPF on the data before searching for the peaks
Cite As
Yonathan Nativ (2024). local maxima \ minima (https://www.mathworks.com/matlabcentral/fileexchange/14498-local-maxima-minima), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- MATLAB > Graphics > 2-D and 3-D Plots > Contour Plots >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 | I added an option to exclude plateau points - I do it by adding noise which won't affect the real peaks position. As it is rather heavy you might not want to use this (default option is off). |