matlab - 在MATLAB中，使用findpeaks和minpeakdistance来查找按距离而不是索引分隔的峰值

``````
[pks,locs] = findpeaks(yData,...
'SortStr','descend',...
'MinPeakDistance',floor(range(xData)/4),...
'MinPeakHeight',floor(max(yData)/2)...
)

``````

``````
>> locs

locs =

6774 166785 326792 486799
>> xData(locs)

ans =

-96780.787939025 -96770.1800919265
-96770.8959353367 -96771.6117787468

``````

findpeaks不知道x坐标，或者你画的是什么，你需要根据索引指定`MinPeakDistance`，下面是一个示例：

``````
xData = -100:1:-1;
yData = rand(1,100);
yData(10) = 100; % peak
yData(11) = 99; % not a peak
yData(50) = 100; % peak
yData(51) = 99; % not a peak
[pks,locs] = findpeaks(yData,...
'SortStr','descend',...
'MinPeakDistance',floor(length(yData)/4),...
'MinPeakHeight',floor(max(yData)/2)...
);

xLocs = xData(locs);

pks =

100 100

locs =

10 50

``````

``````
%find all peaks significantly above noise floor
[pks,locs] = findpeaks(yData,'SortStr','descend','MinPeakHeight',floor(max(yData)/2));
xLocs = xData(locs);

%find number of peak clusters
numPeaks = length(unique(round(xLocs/100)));

%find locations of numPeaks peaks
[pks,locs] = findpeaks(yData,'SortStr','descend','npeaks',numPeaks);

``````