这里显示的2D空间中简单的Matlab三次样条插值的R等价物是什么,即
n = 7;
x = rand(n,1);
y = rand(n,1);
plot(x,y,'.')
axis([0 1 0 1])
t = 1:n;
ts = 1:1/10:n;
xs = spline(t,x,ts);
ys = spline(t,y,ts);
hold on
plot(xs,ys,'r');
hold off
Run Code Online (Sandbox Code Playgroud)
我已尝试过R中的变体,但它们似乎需要对x向量进行排序,并且挖掘相关问题并没有让我更进一步.谢谢...
koh*_*ske 10
可能这是R版本:
n <- 7
x <- runif(n)
y <- runif(n)
t <- 1:n
ts <- seq(1, n, by = 1/10)
xs <- splinefun(t, x)(ts)
ys <- splinefun(t, y)(ts)
plot(x, y, xlim = c(0, 1), ylim = c(0, 1))
lines(xs, ys)
Run Code Online (Sandbox Code Playgroud)
请注意,我不确定样条的算法是否与matlab完全相同.
