在Matlab中找到最高未知峰值点数

时间:2016-11-03 07:40:45

标签: matlab histogram

我想在下面的直方图中找到最高峰值点。例如,如图所示,我应该选择4个峰值点,但是在看到直方图后我得到了这4点信息,所以我需要通过编码找到它。有没有什么方法或算法可以解决这个问题?

enter image description here

如果我手动选择,我可以解决问题。但是,我不知道最高峰值的数量。实际上,主要问题是确定一个门槛。

[pks,locs] = findpeaks(difference)
[sortedX,sortingIndices] = sort(difference,'descend');
locsize=size(locs,2);
counter=1;
peak_order=[];
while counter<5
    for j=1:locsize
        if sortingIndices(counter)==locs(j)            
            peak_order(counter)=sortingIndices(counter);
            counter=counter+1;
        end
    end
end

sorted_peak_order=sort(peak_order)enter code here

1 个答案:

答案 0 :(得分:2)

findpeaks已a series of options来优化您的搜索结果。在您的情况下,选项'MinPeakProminence'应该工作;根据峰值对其邻居的重要性来确定阈值。

[pks,locs] = findpeaks(difference,'MinPeakProminence',0.25*max(difference))