-2

我有两组 x,y 数据。这些数据的曲线如下图所示:

在此处输入图像描述

比方说,如果蓝线是参考,我如何计算蓝线和红线之间的距离?为了更清楚,如果红线在蓝线后面,则差异将为负,反之亦然。

我试过使用 pdist,但我认为这不是我想要的解决方案。

任何帮助将不胜感激。谢谢

4

1 回答 1

4

计算每个时间步的轨迹 a 之间的欧几里得距离非常简单,困难的部分是对该距离进行签名。一种可能性是使用叉积。

这是我的代码:

% --- Define and display sample curves
x1 = cumsum(rand(100,1)-0.3);
y1 = cumsum(rand(100,1)-0.3);

x2 = cumsum(rand(100,1)-0.3);
y2 = cumsum(rand(100,1)-0.3);

subplot(1,2,1)
plot(x1, y1, x2, y2)

% --- Get the distance
d = sqrt((x2-x1).^2 + (y2-y1).^2);

% --- Sign the distance with cross product
u = [x1(:) y1(:)];
u(:,3) = 0;

v = [x2(:) y2(:)];
v(:,3) = 0;

tmp = cross(u, v);
d = d.*sign(tmp(:,3));

% --- Display the result
subplot(1,2,2)
plot(d)

这给了我以下结果(右图):

结果

最好的,

于 2015-03-07T17:09:00.030 回答