仅找到高于阈值的最高峰 [英] Finding the highest peak above threshold only

查看:127
本文介绍了仅找到高于阈值的最高峰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if (pbcg(k+M) > pbcg(k-1+M) && pbcg(k+M) > pbcg(k+1+M) && pbcg(k+M) > threshold)

    peaks_y(Counter) = pbcg(k+M);

    peaks_x(Counter) = k + M;

    py = peaks_y(Counter);
    px = peaks_x(Counter);


    plot(px,py,'ro');
    Counter = (Counter + 1)-1;

    fid = fopen('y1.txt','a');
    fprintf(fid, '%d\t%f\n', px, py);
    fclose(fid);
  end
end

此代码以前在查找峰值方面没有任何问题. 找到唯一峰的主要因素是 如果(pbcg(k + M)> pbcg(k-1 + M)&& pbcg(k + M)> pbcg(k + 1 + M)&&pbcg(k + M)>阈值) 但现在它会一直显示所有高于阈值的峰,而不是特定的最高峰.

this code previously doesn't have any issue on finding the peak.. the main factor for it to find the only peak is this if (pbcg(k+M) > pbcg(k-1+M) && pbcg(k+M) > pbcg(k+1+M) && pbcg(k+M) > threshold) but right now it keep show me all the peak that is above the threshold instead of the particular highest peak..

更新:如果最高峰的4个节点具有相同的值怎么办?

UPDATE: what if the highest peaks have 4nodes that got the same value?

如果出现多个具有相同值的峰,我将在中间取值并作图.

If multiple peaks with the same value surface, I will take the value at the middle and plot.

例如,我的意思是[1,1,1,4,4,4,2,2,2]

What I mean by that is for example [1,1,1,4,4,4,2,2,2]

我将在第5个位置使用"4",因此绘图将位于您看到的图形的中心

I will take the '4' at the 5th position, so the plot will be at the center of the graph u see

推荐答案

使用内置的

It will be much faster and much more readable to use the built-in max function, and then test if the max value is larger than the threshold.

[C,I] = max(pbcg);
if C > threshold
    ... 
    %// I is the index of the maximal value, and C is the maximal value.
end

这篇关于仅找到高于阈值的最高峰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆