local maxima \ minima

版本 1.0.0.0 (1.0 KB) 作者: Yonathan Nativ
a simple (but effective) code to find local maximas
14.3K 次下载
更新时间 2007/9/20

无许可证

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 (2026). local maxima \ minima (https://ww2.mathworks.cn/matlabcentral/fileexchange/14498-local-maxima-minima), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R14SP2
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Contour Plots 的更多信息
版本 已发布 发行说明
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).