MATLAB中有自带的三次样条插值函数
- 插值函数:spline,调用方法: yk =
spline(x,y,xk)
例子:
% 读取插值数据 a = load('data.txt'); x = a(:,1); y = a(:,2); xx = linspace(max(x),min(x),100); yy = spline(x,y,xx); %三次样条插值 % 保存插值结果 fileID = fopen('result.txt','w+'); fprintf(fileID,'%4s %12s\r\n','xx','yy'); fprintf(fileID,'%6.2f %12.8f\n',xx,yy); fclose(fileID) %画图 plot(x,y,'o',xx,yy,'-r') legend('true','cubicSpline') saveas(gcf,'out.jpg')
data.txt
1 93 30 96 60 84 90 84 120 48 150 38 180 51 210 57 240 40 270 45 300 50 330 75 360 80 390 60 420 72 450 67 480 71 510 7 540 74 570 63 600 69
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/217574.html原文链接:https://javaforall.net
