# how to extract the formula from fit function?

36 Ansichten (letzte 30 Tage)
Amin Tehrani am 29 Nov. 2017
Kommentiert: Walter Roberson am 16 Apr. 2024
I want to use fit function to get the formula with its coefficient for my data. so i have used: [curve, goodness, output] = fit(fk,Rfft,'linearinterp'); in case of 'poly1' or 'poly2' the curve variable (which is in cfit format) shows the formula with its coefficients however when i use linearinterp the curve does not show the formula, it just says "piecewise polynomial". i need to get the formula with its coefficients. does anyone have any idea how to get the formula?
<<
>>
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Vishwas am 7 Dez. 2017
There really isn't a formula for the surface. It's a piecewise linear surface so it's a single formula for a plane at each location of your data making it many formulas altogether.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (1)

Bowen Song am 16 Mär. 2019
Bearbeitet: Bowen Song am 16 Mär. 2019
Treat it as a string... lol check this out
[fitresult{1}, gof(1)] = fit( [xData, yData], zData, ft );
... from above you get your sfit or what not
f = string(formula(fitresult{1})); // get the formular in string format
names = coeffnames(fitresult{1}); // get the coeff names
vals = coeffvalues(fitresult{1}); // get those values
for i = 1:length(names)
f = strrep(f,string(names(i)),string(vals(i))); // replace the coeff names with values
end
eval(f) // muhaha
##### 3 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Xiyan Li am 16 Apr. 2024
I wonder how to get the equation out after piecewise fitting? It makes no sense to me without gettting the equation out.
Walter Roberson am 16 Apr. 2024
The output is a piecewise polynomial. It does not have a single equation. It is effectively a list of equations that are each valid over a specific range.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by