How can I fix "Index exceeds the number of array elements (1)."

조회 수: 1 (최근 30일)
Aimee Jin
Aimee Jin 2020년 10월 16일
댓글: Aimee Jin 2020년 10월 16일
This is my script.
function [ca, depth] = transientDiffModel(B,Ds,H,ct,dz,t,th)
B= input(' B:degradation rate of antibiotic in biofilm, in s^-1: ');
Ds= input('Ds:diffusion constant of antibiotic, in mm^2/s:');
H= input('H: total depth of biofilm, in mm:');
ct= input('ct: strength of source of antibiotic at z=0, in ug*mm/L:');
dz= input('dz: step size in depth for simulation, in mm:');
t= input('t: time at which concentration profile is being computed, in s:');
th= input('th: threshold below which a concentration is considered to be zero, in ug/L:');
n=1;
z(1)=0;
ca(1)=ct/sqrt(4*pi*Ds*t)*exp(-B*t);
while ca(n)>=th || z(n)<H;
n=n+1;
z(n)=z(n)+dz;
ca(n)=ct/sqrt(4*pi*Ds*t)*exp(-z(n)^2/(4*Ds*t)-B*t);
end
end
When I run the code, it says:
Index exceeds the number of array elements (1).
Error in transientDiffModel (line 33)
z(n)=z(n)+dz;

답변 (1개)

KSSV
KSSV 2020년 10월 16일
편집: KSSV 2020년 10월 16일
Modify it to:
function [ca, depth] = transientDiffModel(B,Ds,H,ct,dz,t,th)
B= input(' B:degradation rate of antibiotic in biofilm, in s^-1: ');
Ds= input('Ds:diffusion constant of antibiotic, in mm^2/s:');
H= input('H: total depth of biofilm, in mm:');
ct= input('ct: strength of source of antibiotic at z=0, in ug*mm/L:');
dz= input('dz: step size in depth for simulation, in mm:');
t= input('t: time at which concentration profile is being computed, in s:');
th= input('th: threshold below which a concentration is considered to be zero, in ug/L:');
n=1;
z(1)=0;
ca(1)=ct/sqrt(4*pi*Ds*t)*exp(-B*t);
while ca(n)>=th || z(n-1)<H;
n=n+1;
z(n)=z(n-1)+dz;
ca(n)=ct/sqrt(4*pi*Ds*t)*exp(-z(n-1)^2/(4*Ds*t)-B*t); % decide here z(n) or z(n-1)
end
end

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by