[如果x坐标从增加到减少,则使用splines()会产生问题

问题描述 投票:0回答:1

我有两列数据,xy。现在,我想按它们在列中出现的顺序连接这些数据点。假设我有x=[1 2 3 4 3 2]y=[3 4 2 1 3 3]。现在,如果我使用样条曲线创建平滑曲线,它将以递增的顺序对列进行“排序”。我希望它仅获取数据点,因此首先要x(1),y(1)并将它们连接到x(2), y(2),依此类推。

这可能吗?

matlab interpolation curve spline
1个回答
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,'-');

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.