Curve Fitting Using External Function

6 views (last 30 days)
Saeid on 6 Oct 2021
Commented: Image Analyst on 18 Oct 2021
Using the Curve Fitting Toolbox, is it possible to put the fitting function outside of the fittype? A general example of the way I want this to be is:
FitOpt=fitoptions('Method', 'NonlinearLeastSquares','Lower',0.1*Y00, 'Upper',10*Y00,'StartPoint',Y00);
XYFit=fittype(MyFitFunction(a,X),'dependent', {'y'}, 'independent' , {'x'},'coefficient', {'E'});
f1 = fit(x0,y0,XYFit,FitOpt)
function F0=MyFitFunction(a,x)
Where I would like MyFitFunction to be outside the fittype definition, but when I try this I get this error message:
Unrecognized function or variable 'a'
If I take the function into the fittype and write:
XYFit=fittype(@(a,X) a*x.^2-1./x),'dependent', {'y'}, 'independent' , {'x'},'coefficient', {'E'});
then it will work, but this is not the form that I want.
How is this possible?

Answers (1)

Image Analyst
Image Analyst on 7 Oct 2021
Did you try
Image Analyst
Image Analyst on 18 Oct 2021
Call tech support because I don't have that function.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!