我有两列数据,x
和y
。现在,我想按它们在列中出现的顺序连接这些数据点。假设我有x=[1 2 3 4 3 2]
和y=[3 4 2 1 3 3]
。现在,如果我使用样条曲线创建平滑曲线,它将以递增的顺序对列进行“排序”。我希望它仅获取数据点,因此首先要x(1),y(1)
并将它们连接到x(2), y(2)
,依此类推。
这可能吗?
spline
生成从实数到实数的函数。这意味着不能将更一般的曲线表示为y = f(x)
,但我们需要将其参数化为(x(t), y(t))
:
x=[1 2 3 4 3 2];
y=[3 4 2 1 3 3];
plot(x,y,'o-');
% cannot be represented as function y=f(x)
% because x=2 and 3 have two different y values
% -> parametrize x and y:
t = 1:numel(x);
tt = linspace(min(t), max(t), 1000);;
tx = spline(t,x,tt);
ty = spline(t,y,tt);
hold on
plot(tx,ty,'-');