在MATLAB中平滑测量数据?

时间:2014-02-18 20:32:23

标签: algorithm matlab curve measurement monotone

我测量了MATLAB的数据,我想知道如何最好地平滑数据? 示例数据(第1列= x-data / second-colum = y-data):

    33400       209.11
    34066       210.07
    34732        212.3
    35398       214.07
    36064       215.61
    36730       216.95
    37396       218.27
    38062       219.52
    38728       220.11
    39394       221.13
    40060        221.4
    40726       222.5
    41392       222.16
    42058       223.29
    42724       222.77
    43390       223.97
    44056       224.42
    44722        225.4
    45388       225.32
    46054       225.98
    46720       226.7
    47386       226.53
    48052       226.61
    48718       227.43
    49384       227.84
    50050       228.41
    50716       228.57
    51382       228.92
    52048       229.67
    52714       230.02
    53380       229.54
    54046       231.19
    54712       231.00
    55378        231.5
    56044        231.5
    56710       231.79
    57376       232.26
    58042       233.12
    58708       232.65
    59374       233.51
    60040       234.16
    60706       234.21

第二列中的数据应该是单调的,但事实并非如此。如何使它顺利? 我本可以自己发明一个简短的算法,但我认为这是一种更好的方法来使用已建立且经过验证的算法......你知道一种很好的方法可以某种方式整合大纲,使其成为单调曲线! ?

提前致谢

1 个答案:

答案 0 :(得分:1)

你个案中的单调总是在增加!

参见下面的选项(1. Cobb-Douglas; 2. Quadratic; 3. Cubic)

    clear all
    close all

    load needSmooth.dat % Your data

    x=needSmooth(:,1);
    y=needSmooth(:,2);
    n=length(x);

    % Figure 1
    logX=log(x);
    logY=log(y);
    Y=logY;
    X=[ones(n,1),logX];
    B=regress(Y,X);
    a=exp(B(1,1));
    b=B(2,1);
    figure(1)
    plot(x,y,'k*')
    hold
    for i=1:n-1
      plot([x(i,1);x(i+1,1)],[a*x(i,1)^b;a*x(i+1,1)^b],'k-')
    end    


    %Figure 2

    X=[ones(n,1),x,x.*x];
    Y=y;
    B=regress(Y,X);
    c=B(1,1);
    b=B(2,1);
    a=B(3,1);
    figure(2)
    plot(x,y,'k*')
    hold
    for i=1:n-1
      plot([x(i,1);x(i+1,1)],[c+b*x(i,1)+a*x(i,1)^2; c+b*x(i+1,1)+a*x(i+1,1)^2],'k-')
    end    

%Figure 3

X=[ones(n,1),x,x.*x,x.*x.*x];
Y=y;
B=regress(Y,X);
d=B(1,1);
c=B(2,1);
b=B(3,1);
a=B(4,1);
figure(3)
plot(x,y,'k*')
hold
for i=1:n-1
  plot([x(i,1);x(i+1,1)],[d+c*x(i,1)+b*x(i,1)^2+a*x(i,1)^3; d+c*x(i+1,1)+b*x(i+1,1)^2+a*x(i+1,1)^3],'k-')
end    

在Matlab中也有一些煮熟的函数,例如“smooth”和“spline”,它们也适用于你的情况,因为你的数据几乎是单调的。

相关问题