在MATLAB中如何找到匹配两条曲线的比例因子? [英] how to find out the scaling factors to match two curves in matlab?

查看:501
本文介绍了在MATLAB中如何找到匹配两条曲线的比例因子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个在不同日期获得的数据集.我从两个不同的数据集获得的结果具有相似的形状但值不同(参见图1).我想通过将x的y中的常量 A 和y的 B 相乘,将第二个数据集(x2,y2)与第一个数据集(x1,y1)匹配.第二个数据(请参见图2).

I have two data sets obtained at different days. The results I got from two different data sets have similar shape but different values (see fig1). I am trying to match the second data set (x2,y2) to the first one (x1,y1) by multiply a constant A in x and B in y of the second data (see fig2).

例如:

数据1:

x1 = [-0.3:0.06:2.1]';

x1=[-0.3:0.06:2.1]';

y1 = [0.001 0.001 0.004 0.014 0.052 0.166 0.330 0.416 0.340 0.247 0.194 0.197 0.237 0.330 0.428 0.542 0.669 0.767 0.855 0.900 0.913 0.904 0.873 0.811 0.765 0.694 0.631 0.585 0.514 0.449 0.398 0.351 0.309 0.273 0.233 0.211 0.182 0.154 0.137 0.117 0.101 ]';

y1=[ 0.001 0.001 0.004 0.014 0.052 0.166 0.330 0.416 0.340 0.247 0.194 0.197 0.237 0.330 0.428 0.542 0.669 0.767 0.855 0.900 0.913 0.904 0.873 0.811 0.765 0.694 0.631 0.585 0.514 0.449 0.398 0.351 0.309 0.273 0.233 0.211 0.182 0.154 0.137 0.117 0.101 ]';

data2

x2 = [-0.3:0.06:2.1]';

x2=[-0.3:0.06:2.1]';

y2 = [0.000 0.000 0.000 0.000 0.025 0.230 0.447 0.425 0.269 0.194 0.225 0.326 0.477 0.636 0.791 0.931 1.036 1.104 1.117 1.123 1.062 0.980 0.897 0.780 0.675 0.571 0.471 0.390 0.309 0.258 0.209 0.161 0.129 0.099 0.079 0.063 0.047 0.038 0.027 0.023 0.015 ]';

y2=[0.000 0.000 0.000 0.000 0.025 0.230 0.447 0.425 0.269 0.194 0.225 0.326 0.477 0.636 0.791 0.931 1.036 1.104 1.117 1.123 1.062 0.980 0.897 0.780 0.675 0.571 0.471 0.390 0.309 0.258 0.209 0.161 0.129 0.099 0.079 0.063 0.047 0.038 0.027 0.023 0.015 ]';

要找出比例系数 A & B ,我正在考虑通过最小化data1和x修改后的data2之间的增量来获得 B .不过,我确实有一种很好的方法来找出A.我应该如何找出 A & B 来匹配这两条曲线?任何帮助,我们将不胜感激.

To find out the scaling factor A & B, I am thinking about obtaining B by minimizing the delta y between data1 and x modified data2. However I do have a good way to find out the A. How should I find out the A & B to match this two curve? Any help is greatly appreciated.

推荐答案

如果您具有优化工具箱(或访问任何不受约束的非线性最小化例程),则可以执行以下操作:

If you have the optimization toolbox (or access to any unconstrained non-linear minimization routine), you can do the following:

定义一个计算两条曲线之间的误差的函数

Define a function that computes the error between your two curves

function err = sqrError(coeffs, x1, y1, x2, y2)
    % Interpolation of 'y2' with scaled 'x2' into the domain 'x1' 
    y2sampledInx1 = interp1(coeffs(1)*x2,y2,x1);
    % Squred error calculation
    err = sum((coeffs(2)*y2sampledInx1-y1).^2);
end

使用fminunc(或任何可用的优化程序)来计算系数:

Use fminunc (or whatever optimizer you have available) to compute your coeffiecients:

coeffs = fminunc(@(c) sqrError(c,x1, y1, x2, y2),[1;1]);

A = coeffs(1);
B = coeffs(2);
plot(x1, y1, A*x2, B*y2)

这篇关于在MATLAB中如何找到匹配两条曲线的比例因子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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