fitting 1D data to y=x polynomial (cftool)

In an experiment vector y is a measurement of vector x. I want to fit polynomial y=x to this data and find R^2. When I use polyfit(x,y,1), MATLAB gives me y=ax+b but I am interested in knowing the R^2 when the data is fitted to y=x. Could someone please help me on that?
I found cftool which can solve my problem. Could someone tell me how I can retrieve R^2 from the analysis of cftool when the data is fitted to a polynomial?
Thanks.

댓글 수: 1

Jesús Lucio
Jesús Lucio 2011년 9월 5일
Hello. I think you only have to evaluate the fitted polynomial at the same abscissas and compare with the original ordinates:
poly = polyfit(x, y, 1);
yfit = polyval(poly, x);
cc = corrcoef(y, yfit);
R2 = cc(1, 2).^2;

댓글을 달려면 로그인하십시오.

답변 (1개)

Sean de Wolski
Sean de Wolski 2011년 7월 7일

0 개 추천

댓글 수: 5

AP
AP 2011년 7월 7일
I know how to fit y=ax+b but I want to fit the curve y=x to my data. Do you know how I can use cftool at MATLAB command prompt?
Sean de Wolski
Sean de Wolski 2011년 7월 7일
No reason for cftool. Did you look at Matt's answer?
AP
AP 2011년 7월 7일
I did. But it does not fit to y=x. It fits it to y=mx+b. I solved my problem by using fit command.
Sean de Wolski
Sean de Wolski 2011년 7월 7일
All you need to do is change the vandermonde matrix, in his example 'F'
Sean de Wolski
Sean de Wolski 2011년 7월 7일
For zeroth order fit; i.e. what you want, it will just be x.^0, aka ones(size(x)) aka the mean.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

태그

질문:

AP
2011년 7월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by