How to get coefficients result from the code which is generated from curve fitting tool??
Show older comments
I'm just want to do curve fitting, but it doesn't work as I want.
I ran a curve fitting tool with some conditions, and the result was plausible.
And now I want to do it in the command line because I want to do it automatically.
To do that, I utilize the "code generate" in the Curve Fitting Tool.
But there is no information about coefficients in the generated code. (in the tool box I can see the result coefficients)
How can I obtain coefficients from the Curve Fitting Tool??
the generated Code is as below.
%===============================================================================
%%Fit: 'untitled fit 1'.
[xData, yData, zData] = prepareSurfaceData( soc_cur, time_cur, y );
% Set up fittype and options.
ft = fittype( '(a0*exp(a1*x) + a2 + a3*x + a4*x.^2 + a5*x.^3) - ( 2.2*(b0*exp(b1*x) + b2) + (0.31 - 2.2)*(c0*exp(c1*x) + c2).*exp(-y./((c0*exp(c1*x) + c2).*(d0*exp(d1*x) + d2))) + 2.2 * (c0*exp(c1*x) + c2) + (0.31 - 2.2)*(e0*exp(e1*x) + e2).*exp(-y./((e0*exp(e1*x) + e2).*(f0*exp(f1*x) + f2))) + 2.2 * (e0*exp(e1*x) + e2));', 'independent', {'x', 'y'}, 'dependent', 'z' );
opts = fitoptions( ft );
opts.Display = 'Off';
opts.Lower = [-Inf -Inf 0.0001 0.0001 -Inf 0.0001 0.0001 -Inf 0.0001 0.0001 -Inf 0.0001 -Inf -Inf 0.0001 0.0001 -Inf 0.0001 -Inf -Inf 0.0001];
opts.StartPoint = [-1 -1 1 1 -1 1 1 -1 1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 1];
opts.Upper = [-0.0001 -0.0001 Inf Inf -0.0001 Inf Inf -0.0001 Inf Inf -0.0001 Inf -0.0001 -0.0001 Inf Inf -0.0001 Inf -0.0001 -0.0001 Inf];
% Fit model to data.
[fitresult, gof] = fit( [xData, yData], zData, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, [xData, yData], zData );
legend( h, 'untitled fit 1', 'y vs. soc_cur, time_cur', 'Location', 'NorthEast' );
% Label axes
xlabel( 'soc_cur' );
ylabel( 'time_cur' );
zlabel( 'y' );
grid on
view( -39.5, 30 );
<<C---Users--ELPL--Desktop--test.jpg>>
Thanks in advance.
Accepted Answer
More Answers (0)
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!