Matlab:在单个图像中查找多条曲线的峰值

时间:2015-07-31 13:46:29

标签: matlab max matlab-figure

图中有三条曲线,我无法找到这三条曲线的峰值。

如何找到峰值?

以下是(x,y)值。

>> [x,y]
ans =
 1    86
 5    91
 8    94
12    98
15   101
19   103
21   104
23   105
28   106
28   184
31   191
34   105
39   103
41   101
41   210
42   212
43   214
44    99
45   215
47    96
48   216
49    93
51   215
54    87
54   213
56    84
56   210
60    78
65   191
66    43
68   184
69    47
71    49
73    52
73    54
77    56
82    60
85    62
87    63
89    64
92    65
98    66
104    65
107    64
109    63
112    62
114    60
119    56
125    49
127    47
130    43

绘制时会给出3条不同的曲线。但是,虽然找到最大值只返回最高曲线的峰值。

2 个答案:

答案 0 :(得分:1)

这是一个快速而肮脏的解决方案,绝对不是一般的,绝对是慢的,并且可能只节省一点点的手工工作。它沿着你的x向量,并尝试根据连续点的距离将点分类为等价类。这可能比solution of anon0909更为通用,但对于分离度较低的数据仍然可能失败,并且需要手动调整才能正确选择半径。 代码:

%sort to be on the safe side
[x inds]=sort(x);
y=y(inds);

eqradius=15; %the key parameter

equivs=[];
equivs(1).ind=1;
equivs(1).x=x(1); %redundant but useful
equivs(1).y=y(1); %redundant but useful

for i=2:length(x) % go over remaining points
    foundone=0;
    for eqclass=1:length(equivs) %go over found equivalence classes
        if norm([x(i) y(i)] - [equivs(eqclass).x(end) equivs(eqclass).y(end)])<eqradius
            foundone=1;
            equivs(eqclass).ind = [equivs(eqclass).ind; i];
            equivs(eqclass).x = [equivs(eqclass).x; x(i)];
            equivs(eqclass).y = [equivs(eqclass).y; y(i)];
        end
        if foundone==1
            break %break eqclass if
        end
    end

    if ~foundone
        equivs(length(equivs)+1).ind = i;
        equivs(length(equivs)).x = x(i);
        equivs(length(equivs)).y = y(i);
    %else
    %    continue % but the loop is already over
    end
end

%plot classes
figure;
eqclass=1;
hold all;
legendcell={};
for eqclass=1:length(equivs)
    plot(equivs(eqclass).x,equivs(eqclass).y,'o');
    legendcell{end+1}=num2str(eqclass);
end
legend(legendcell);

enter image description here

正如您所看到的,在eqradius=15的情况下,我们无意中将曲线编号2分成3个单独的等价类,因此您仍然需要一些手工劳动。或者你可以尝试增加eqradius,但这最终会导致你的曲线互相污染。

当这是一个比引用的更好的解决方案时,唯一的情况是,当你有两条曲线在同一y频段但在x中分开时......

答案 1 :(得分:0)

这些问题非常依赖于您可以/不能假设的数据集中的功能,以及您希望在代码中自动执行的程度。但是,根据您提供的数据,您可以简单地将每个凹凸区域与y值分开,并获取子集的每个最大值。即,像这样:

y1 = y(y<=75);
y2 = y(75<y<=150);
y3 = y(y>150);
max1 = max(y1);
max2 = max(y2);
max3 = max(y3);