local maxima \ minima
无许可证
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
引用格式
Yonathan Nativ (2024). local maxima \ minima (https://www.mathworks.com/matlabcentral/fileexchange/14498-local-maxima-minima), MATLAB Central File Exchange. 检索来源 .
MATLAB 版本兼容性
平台兼容性
Windows macOS Linux类别
- MATLAB > Graphics > 2-D and 3-D Plots > Contour Plots >
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!版本 | 已发布 | 发行说明 | |
---|---|---|---|
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). |