所示的 2D 空间中简单 Matlab 三次样条插值的 R 等效项是多少here http://www.mathworks.de/products/matlab/demos.html?file=/products/demos/shipping/matlab/spline2d.html, i.e.
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
我尝试过 R 的变体,但它们似乎需要 x 向量的排序,并且深入研究相关问题并没有让我进一步。谢谢...
可能这是 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)
请注意,我不确定 spline 的算法是否与 matlab 完全相同。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)