error in mdl/rsquared.ordniary

조회 수: 6(최근 30일)
Noa Prasquier
Noa Prasquier 2021년 5월 8일
댓글: Noa Prasquier 2021년 5월 16일
Hi,
I am trying to use fitlm and rsquared ordinary functions and I can't figure out where the errors comes from.
Moreover, I want to plots 3 graphs but only the first one appears.
I would really appreciate your help.
here is my code :
function[]=reaction_order(A)
fit0=A;
fit1=log(A);
fit2=1./A;
time=[1:11]';
f0=fit(time,fit0','poly1');
figure
plot(f0,time,fit0);
xlabel('Time [s]');
ylabel('A [M]')
title('Zero order fit, A concentration as a function of time')
legend('A concentration', 'Fit curve')
mdl0=fitlm(time,f0);
rsquared0=mdl0.Rsquared.ordinary;
fprintf(rsquared0)
f2=fit(time,fit2','poly1');
figure;
plot(f2,time,fit2);
xlabel('Time [s]');
ylabel('1/A [1/M]')
title('Second order fit, 1/A as a function of time')
legend('1/A', 'Fit curve')
mdl2=fitlm(time,f2);
rsquared2=mdl2.Rsquared.ordinary;
The error is :
Error using classreg.regr.FitObject/assignData (line 134)
Predictor and response variables must have the same length.
Error in classreg.regr.TermsRegression/assignData (line 245)
model =
assignData@classreg.regr.ParametricRegression(model,X,y,w,asCat,varNames,excl);
Error in LinearModel.fit (line 1030)
model =
assignData(model,X,y,weights,asCatVar,dummyCoding,model.Formula.VariableNames,exclude);
Error in fitlm (line 121)
model = LinearModel.fit(X,varargin{:});
Error in chimieq2>reaction_order (line 50)
mdl0=fitlm(time,f0);
Error in chimieq2 (line 4)
reaction_order(A)

답변(1개)

Sindhu Karri
Sindhu Karri 2021년 5월 12일
Hii,
The error is in the line
mdl0=fitlm(time,f0);
It is because of passing incorrect inputs to the fitlm function,here the error message
"Predictor and response variables must have the same length"
refer to the variables time and f0.Refer to below attach for more details on fitlm function
And the reason for getting only one graph is because of this error and other two plots have not been calculated.
  댓글 수: 1
Noa Prasquier
Noa Prasquier 2021년 5월 16일
ok, do you know what input I am supposed to pass to the fitlm?

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

Community Treasure Hunt

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

Start Hunting!

Translated by