After curvefitting data, can I import the "fitresult" text (cfit) into the plot figure, also can I export the coefficients to excel

조회 수: 7 (최근 30일)
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)

답변 (1개)

Javier Bastante
Javier Bastante 2016년 3월 16일
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

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by