【问题标题】:Find distance of one graph from another in matlab在matlab中查找一个图与另一个图的距离
【发布时间】:2017-02-10 18:48:46
【问题描述】:

我在 Matlab 中有两条曲线。

曲线 A:

x1 = [128 192   256 384 512 704 1024 1472 2048 2880 4096 5824 8192 11584 16384 23168];
y1 = [0.62 0.51 0.43 0.35 0.3 0.26 0.22 0.18 0.15 0.13 0.11 0.09 0.08 0.06 0.05 0.05];

曲线 B:

x2 = [16 24 32 48 64 88 128 184 256 360 512 728 1024 1448 2048 2896];
y2 = [1.94 1.54 1.33 1.15 0.97 0.86 0.71 0.59 0.5 0.42 0.36 0.3 0.25 0.21 0.18 0.15];

在同一个图中绘制两条曲线(x 轴指数)后:

semilogx(x1,y1,'-o')
hold on
semilogx(x2,y2,'-o')

我发现 B 曲线高于 A 曲线。但我想将 B 向左移动,使 B 曲线与 A 曲线重叠。所以问题是,我需要将 B 曲线移动多少(从右到左)才能与 A 曲线重叠?

一些线索:可能需要计算从 B 到 A 的垂直距离(对于所有匹配点)(插值)并将距离平方并将它们全部相加并找到 Alpha 的值。我如何在 Matlab 中做到这一点?

【问题讨论】:

  • 看数据,好像y1
  • 不!这将使它们彼此远离。我想计算距离(插值)。
  • 本例中的预期输出是什么?

标签: matlab


【解决方案1】:

我们可以通过首先找到 x2 的哪些值将曲线 B 移动到曲线 A 的顶部来找到所需的偏移。这可以通过在对应于 y 坐标的点处重新采样曲线 A 来实现曲线 B。下面的代码说明了这一点。

由于您在对数域中绘制 x 轴,我假设您想要移动 log10(x2)。因此,移动曲线上的 x 点将是 log10(x2) + shift 而不是 log10(x2 + shift)

% find the subset of y2 which is within the range of y1
idxCommonB = find((y2 <= max(y1)) & (y2 >= min(y1)));
y2c = y2(idxCommonB);
x2c = x2(idxCommonB);

% for each point on curve B, find a new x2 that would move the point on
% curve A
% We use interp1 function for resample the curve. This function requires
% all the points in the domain to be unique. So find the unique elements in
% y1.
[y1_unique,iUnique] = unique(y1);
x2c_desired = interp1(y1_unique, x1(iUnique), y2c, 'linear');

% find the average distance between the desired and given curves
x2_logshift = mean(log10(x2c_desired) - log10(x2c));

% Display the result
fprintf('Required shift in log10(x2) is %f.\n', x2_logshift);
% Required shift in log10(x2) is -0.126954.    

% plot to verify the estimate
figure;
plot(log10(x1),y1,'-o')
hold on
plot(log10(x2),y2,'-o')
plot(log10(x2)+x2_logshift,y2,':*')
grid on;
legend({'A', 'B', 'Shifted B'});
set(gca, 'FontSize', 12);

【讨论】:

  • 这个解决方案看起来很棒,但我几乎没有这个情节必须回答的问题。 1. 我需要多少移动红色曲线以使其与蓝色曲线重叠。是-0.126吗?壳是负面的吗?我可以在没有 log10 的情况下解决这个问题吗? 2. 在 x 轴上,我需要使用 semilogx() 函数绘制图形(指数)以清楚地显示 x 轴
  • 是的,红色曲线需要在对数域中移动 -0.126 以匹配蓝色曲线。负号表示向左移动。在我看来,这种转变应该在对数域中进行,否则两条曲线之间的匹配会很差。最后,您可以轻松地使用semilogx 进行绘图。请记住,对数尺度的变化相当于线性尺度的乘法。因此,例如,移动的红色曲线可以绘制为:semilogx(x2*10^x2_logshift, y2)
  • 再想一想。在我的真实情况下。 x 轴是判断次数,y 轴是平均置信区间。那么我如何将 -0.126 与判断次数联系起来呢?我可以说移动 B 曲线需要 0.126 次平均判断才能得到与 A 曲线相同的结果吗?听起来对吗?谢谢
  • 没有。请记住,我们估计了对数域的偏移。所以偏移量是乘法的,而不是加法的。更正确的说法是,曲线 A 的判断次数是曲线 B 的 10^-0.126 = 0.75 倍(或比曲线 B 少 25%)。或者在相同的置信区间下,曲线 B 的判断次数是曲线 A 的 10^0.126 = 1.33 倍(或比曲线 A 多 33%)。
  • 所以,如果我们将 0.75 个判断乘以 B,那么我们将拥有与 A 相同的置信区间。
猜你喜欢
  • 1970-01-01
  • 2016-11-06
  • 1970-01-01
  • 2012-11-19
  • 2013-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多