How to extend smoothingspline predictions
4 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/155364/image.jpeg)
I need to extend my best fit curve so that I can get a current prediction when y position = 70 mm, is there a possible way to do this?
clc
clear all
load TOD_regular_lda.mat
x = 1;
for i = 1:1:5
current(x) = mean(lda(x).um);
z(x) = lda(x).z;
C = current;
x = x + 1;
end
C = C(:);
Z = z(:);
% a = fit(C,Z,'poly2');
b = fit(C,Z,'smoothingspline');
plot(C,Z)
axis([-0.05 0 -400 100 ])
hold on
% plot(a,'r--')
plot(b,'g--')
xlabel('Current (m/s)')
ylabel('y position (mm)')
0 个评论
采纳的回答
Anish Mitra
2016-2-22
I cannot comment on the quality of the extension (extrapolation) of the fit, since it depends on the data. However, the 'feval' method can be used with the 'cfit' object that is returned by the 'fit' function.
Following is a sample code to extend the fitted values, and compare them to the original synthetic data.
% Code to test extrapolation for different fit types
% (smoothingspline and quadratic polynomial curve)
clear; close all; clc;
% Generate data for the entire range (to compare the extrapolated result
% later on
x_all = (0:0.01:5)';
y_all = 0.2*x_all.^3 - x_all.^2;
% Obtain fitting data
x_data = x_all(x_all>1 & x_all<4);
y_data = y_all(x_all>1 & x_all<4);
% Fit a smoothing spline
fit_ss = fit(x_data,y_data,'smoothingspline');
% Fit a quadratic polynomial curve
fit_poly = fit(x_data,y_data,'poly2');
% Evaluate the fitted function for the original range using the feval
% function
y_ss = feval(fit_ss,x_all);
y_poly = feval(fit_poly,x_all);
% Plot all data
figure; hold on;
plot(x_all, y_all, 'b');
plot(x_data, y_data, 'g.');
plot(x_all, y_ss,'r');
plot(x_all, y_poly, 'k');
Note that 'SmoothingSpline' is generally not recommended if the objective is to then extrapolate the fit to outside the initial data limits. The following example contains more details on Smoothing Splines.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!