矩形空矩阵0的分配不正确

时间:2013-04-03 21:52:59

标签: matlab matrix

???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

1 个答案:

答案 0 :(得分:0)

<强>提示

我可以通过在脚本顶部设置$ n = 0 $来轻松重现您的错误,因此请考虑在您的情况下$ n = 0 $的原因(进一步提示:检查您的Excel文件中的数据范围)