After curvefitting data, can I import the "fitresult" text (cfit) into the plot figure, also can I export the coefficients to excel
7 views (last 30 days)
Show older comments
ft = fittype( 'a*exp(-b*x)+c', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [1 0.2 0.09];
[fitresult, gof, output] = fit( xData, yData, ft, opts );
h = plot(fitresult, xData, yData)
0 Comments
Answers (1)
Javier Bastante
on 16 Mar 2016
Using this:
coef=coeffvalues(fitresult);
you can save your partameter values in a ROW variable called "coef". The order of the numbers is the order in which your parameters appear on your model (to see it you can use coeffnames(fitresult)).Once you've done this you can save them in excel using xlswrite:
xlswrite(filenamewithfullpath,variable,sheet,range)
So, in this case, for a file called example.xlsx saved in "C:\MATLAB\files\" and you want to save the coefficients in the second sheet, cells A1,A2 and A3 (COLUMN distribution) you must do this:
xlswrite(fillfile('C:\MATLAB\files','example.xlsx'),coef',2,'A1:A3')
You can have more info about all of this and more in:
help xlswsrite
or
doc xlswrite
The only important thing is that the Excel file must be closed. At least I've had always this problem.
If any of this desn't work or you have more questions, please don't hesitate and ask me.
Best Regards
0 Comments
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!