Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab:在单个图像中查找多条曲线的峰值_Matlab_Max_Matlab Figure - Fatal编程技术网

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

Matlab:在单个图像中查找多条曲线的峰值,matlab,max,matlab-figure,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 4

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

如何找到山峰

下面是
(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条不同的曲线。但是,当找到最大值时,只返回最高曲线的峰值。

这些问题取决于数据集中您可以/不能假设的特性,以及您希望在代码中自动化的程度。但是,从您提供的数据来看,似乎可以简单地通过y值分离每个凹凸,并获取子集的每个最大值。也就是说,类似这样的事情:

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

y1=y(y这里有一个快速而肮脏的解决方案,它绝对不是通用的,绝对是慢的,并且可能只节省一点手工工作。它沿着
x
向量,尝试根据连续点的距离将点排序为等价类。这可能比对于分离程度较低的数据,需要手动调整以正确选择半径。 代码:

%排序要安全
[x inds]=排序(x);
y=y(inds);
eqradius=15;%关键参数
当量=[];
当量(1),ind=1;
当量(1).x=x(1);%冗余但有用
当量(1).y=y(1);%冗余但有用
对于i=2:长度(x)%
foundone=0;
对于eqclass=1:长度(当量)%检查找到的当量类

如果norm([x(i)y(i)]-[equivs(eqclass).x(end)equivs(eqclass).y(end)])你总是为每条曲线得到一个峰值吗?也许在每条曲线上单独使用max()会更容易。另外,如果你提供一些代码就好了……这实际上是一组(x,y)值。max()函数只给出一条曲线。但我需要所有三条曲线。你能以某种方式分割曲线,从而得到三条单独的曲线吗?不幸的是,Matlab不“知道”这里有三条曲线……你如何分割曲线呢?(x,y)值是由传感器获得的,不是用户定义的。@lhcgeneva我想这就是重点。可以尝试拟合3个简单多项式的和,但我猜已经失败了。编辑:我意识到数据重叠,我看到了问题……编辑2查看
cumsum(y)如何
,然后将3个移位多项式之和拟合到该值?这有意义吗?不,我想不会……我想一组样本数据在这种情况下会有很大帮助:)
%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);