I keep getting this error:Index exceeds matrix dimensions.

2 次查看(过去 30 天)
I keep getting this error:Index exceeds matrix dimensions. Error in ==> D:\toolbox\matlab\funfun\pdepe.m (pdeodes) On line 338 ==> up(j,i) = (xim(i) * fR(j) - xim(i-1) * fL(j)) + ...
Error in ==> D:\toolbox\matlab\funfun\private\odearguments.m On line 104 ==> f0 = feval(ode,t0,y0,args{:});
Error in ==> D:\toolbox\matlab\funfun\ode15s.m On line 212 ==> [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, args, ...
Error in ==> D:\toolbox\matlab\funfun\pdepe.m On line 287 ==> [t,y] = ode15s(@pdeodes,t,y0,opts,pde,ic,bc,m,xmesh,xi,xim,zxmp1,xzmp1,varargin{:});
Error in ==> D:\work\kinetics.m On line 19 ==> Cis= pdepe(m,@pdecoefsr,@pdeicsr,@pdebcsr,x,t)
the main Mfile names kinetics %input Cio=13.5 ; %initial concentration Rp=.002 ; %radius of particals m epsilon=.5; %porosity kf2 = 0.04; Di=6*10^-8 ; % diffuision coefficient in catalyst k = .035; Ke=4.95 rs=1 Xi=1 taw=Rp^2/Di time=2*60 t=time/taw %initialization m=0 x = linspace(0,1,20); t = [0 0.5 1 1.5 2]; Cis= pdepe(m,@pdecoefsr,@pdeicsr,@pdebcsr,x,t)
function[pl,ql,pr,qr]=pdebcsr(xl,ul,xr,ur,t) global Xi
pl =ul; ql =0; pr =Xi-1; qr =0; end
function [c,b,s]=pdecoefsr(x,t,u,DuDx) global kf2 Rp Cis Ke epsilon Cio
c = 1; b =DuDx; s = -epsilon*kf2*Cio*(Rp^2)*(Cis^2-((1-Cis)/Ke)); end
function u0=pdeicsr(x)
u0=0; end

回答(1 个)

Andrew Reibold
Andrew Reibold 2014-8-8
编辑:Andrew Reibold 2014-8-8
'You cannot try to access part of an array that does not exist yet.
>> A = [1,3];
>> A(3)
Index exceeds matrix dimensions
Unfortunately, MATLAB doesn't tell you which variable you exceeded the dimensions on if there's more than one so you'll have to check that. This often occurs if, for example, you are using a loop to change which part of an array is accessed, but the loop doesn't stop before you reach the end of the array. This also happens if you end up with an empty matrix as a result of some operation and then try to access an element inside it.'
I recommend putting breaks in your code before the error so you can check the index value and check the arrays your are using so that you can identify where the problem is coming from.

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by