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

我试图得到MATLAB中峰值的x坐标图(附加的示例),我一直在使用findpeaks,但我想绘制点,而不是线条。

以下是我期望的工作:


[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

我假设MinPeakDistance正在处理xData索引,而不是数据本身,我如何让它使用峰值之间的距离而不是峰值指数之间的距离?

enter image description here

时间:

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);

...