???Improper assignment with rectangular empty matrix
Error in task3, 18
y(:,1)=log(r);
错误仍然存在,我不知道该怎么办。脚本如下
function task3
time=xlsread('Kinetics_data.xls','B3:B82');
Conc=xlsread('Kinetics_data.xls','C3:C82');
CAo=0.050;
CBo=0.0406;
h=0.5;
n=length(Conc);
%Calculate the reaction rate using the forward difference equation and
%eliminate outliners if necessary.
global CA CB
t=time(2:n-1);
CA=Conc(2:n-1);
CB=CBo-(CAo-CA);
r=(-Conc(3:n)+Conc(1:n-2))/(2*h);
y(:,1)=log(r);
X(:,1)=ones(size(CA));
X(:,2)=log(CA);
X(:,3)=log(CB);
[b bint resid residint stats]=regress(y,X);
b;
bint;
k=exp(b(1));
kint=exp(bint(1,:));
b(1)=k;
% Set initial guess of parameter value.
m0=b;
% Set lower and upper bounds for the parameters
ub=[2.981770068869469 1.515475186852946 0.914563691229481];
lb=[1.354032677809809 0.938815382572068 0.753329300963922];
options=optimset('TolX',1e-16,'TolFun',1e-16,'MaxFunEval',4000,'MaxIter',4000);
[m,residn,resid,exiflage,output,lamda,Jacob]=lsqcurvefit(@ratefun,m0,t,r,lb,ub,options)
end