Renaming Fit rsquare value

조회 수: 5 (최근 30일)
Petch Anuwutthinawin
Petch Anuwutthinawin 2021년 6월 26일
댓글: Scott MacKenzie 2021년 6월 26일
I have made a fit for a set of data. It returns an rsquare value, which I have to rename to R1.
%This is the code for the fit
ft1=fittype('m*x+b');
[Fit1,gof]=fit(A',T',ft1)
%Below is the output for gof. I need to rename rsquare to R1.
gof =
struct with fields:
sse: 2.1928e+03
rsquare: 0.0121
dfe: 8
adjrsquare: -0.1114
rmse: 16.5561

채택된 답변

Scott MacKenzie
Scott MacKenzie 2021년 6월 26일
ft1=fittype('m*x+b');
[Fit1,gof]=fit(A',T',ft1)
R1 = gof.rsquare
  댓글 수: 4
Petch Anuwutthinawin
Petch Anuwutthinawin 2021년 6월 26일
I have multiple fits made, and have to rename each rsquare output from each fit with a different name.
ft1=fittype('m*x+b');
[Fit1,gof]=fit(A',T',ft1)
%% Second order poly
ft2=fittype('a*x.^2+b*x+c');
[Fit2,gof]=fit(A',T',ft2)
%% Third order poly
ft3=fittype('a*x.^3+b*x.^2+c*x+d');
[Fit3,gof]=fit(A',T',ft3)
%The rsquare for Fit1 has to be named R1, the rsquare for Fit2 has to be
%named R2 etc.
Scott MacKenzie
Scott MacKenzie 2021년 6월 26일
I notice that you are not renaming the gof variable returned in each call to fit. So, after the second call, you no longer have gof from the first call. That's fine, but if you want to have all three R-squared values after the three calls to fit, you need to save them in some way. Here's one approach:
ft1=fittype('m*x+b');
[Fit1,gof]=fit(A',T',ft1)
R1 = gof.rsquare; % save 1st R-squared value
%% Second order poly
ft2=fittype('a*x.^2+b*x+c');
[Fit2,gof]=fit(A',T',ft2)
R2 = gof.square; % save 2nd R-squared value
%% Third order poly
ft3=fittype('a*x.^3+b*x.^2+c*x+d');
[Fit3,gof]=fit(A',T',ft3)
R3 = gof.rsquare; % save 3rd R-squared value

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by