# How to get the fitted data by using Matlab's "Fit" Function?

27 Ansichten (letzte 30 Tage)
Zheng am 21 Sep. 2012
For example, by using below code
fitresult = fit( [x, y], z, 'poly33' );
From fitresult, I can get the formula used to fit x,y and z data
But how can I get the fitted data matrix via this "fit" function?
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Wayne King am 22 Sep. 2012
It gives you a 1-D vector, but that 1-D vector is a polynomial in two variables, hence it is a function of the form f(x,y)=z
Calling
formula(fitresult)
shows you exactly what the terms in x and y the coefficients multiply
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (1)

Wayne King am 22 Sep. 2012
Hi, you can use the coeffvalues() method on the fitresult object.
coeffs = coeffvalues(fitresult);
That will give you the coefficients of your polynomial in x and y.
To see how those coefficients enter into the polynomial equation:
formula(fitresult)
##### 2 KommentareKeine anzeigenKeine ausblenden
Zheng am 22 Sep. 2012
Thanks, Wayne. But how can I use this formula to calculate the surface (shown as below)? This formula can only help me get a 1-D vector, not 2-D matrix.
grace am 22 Feb. 2013
May I know what is the code for goodness of fit? coeffs = coeffvalues(fitresult); Similarly, rsquare = code(fitresult); I wanted to get the rsquare values from cftool to display in command window.

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