Matlab Error "Attempted to access -- ; index out of bounds because numel--=???.
3 次查看(过去 30 天)
显示 更早的评论
If my code looks like the following;
time=0; %Initialise time
particleno=9
dt=0.01;
tfinal=40;
diagstep=10;
diagcounter=0;
while time<tfinal
tie=time+dt;
if ((int8(time/diagstep) * diagstep) == int8(time))
[xcounter] = ParticleCounterFun(x0, particleno);
diagcounter=diagcounter+1;
end
Xtcounter(diagcounter)=xcounter(diagcounter);
end %End while time<tfinal LOOP
the FUNCTION FILE FOR PARTICLECOUNTERFUN IS;
function [ xcounter ] = ParticleCounterFun( x0, particleno )
%Initialise counters used in E field diagnostics
counter01=0;
counter12=0;
counter23=0;
counter34=0;
counter45=0;
for np=1:particleno
if (0<=x0(np) & x0(np)<1)
counter01=counter01+1;
end
if (1<=x0(np) & x0(np)<2)
counter12=counter12+1;
end
if (2<=x0(np) & x0(np)<3)
counter23=counter23+1;
end
if (3<=x0(np) & x0(np)<4)
counter34=counter34+1;
end
if (4<=x0(np) & x0(np)<5)
counter45=counter45+1;
end
end
xcounter=[counter01 counter12 counter23 counter34 counter45];
end
Anyway i get this;
>> ParticlePusher Attempted to access xcounter(6); index out of bounds because numel(xcounter)=5.
Error in ParticlePusher (line 101) Xtcounter(diagcounter)=xcounter(diagcounter);
Help please!
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!