How to turn a curve fit into a function
84 ビュー (過去 30 日間)
古いコメントを表示
I have been fitting some data generated in the lab. The best fit is by piecewise polynomial

I would now need to turn this into a function that I can then plug in a model (where I repeat this function with different time delays and then sum them up). What is the best way to do this? If I generate a fit wth the FIT function, I am then unable to use that object as a normal function. Any advice?
2 件のコメント
Steven Lord
2022 年 2 月 2 日
As Matt J and Walter Roberson stated, you can evaluate the fit by treating it like it was a function. This documentation page shows this technique and also some of the other operations you can perform on the object representing the fitted curve.
回答 (2 件)
Matt J
2022 年 2 月 2 日
If I generate a fit wth the FIT function, I am then unable to use that object as a normal function.
Sure you can.
x=1:5;
y=x.^2;
f=fit(x(:),y(:),'poly2')
f(2)
0 件のコメント
Walter Roberson
2022 年 2 月 2 日
If you generate a fit with the fit function, then the result is usable as a function.
fitobj = fit(X(:), Y(:), 'pchip');
xq = linspace(min(X), max(X));
ypred = fitobj(xq); %notice fitobj has been used as if it is a function
plot(X, Y, '*', xq, ypred, '-')
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Linear and Nonlinear Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!