How can I fix "Index exceeds the number of array elements (1)."
1 回表示 (過去 30 日間)
古いコメントを表示
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;
0 件のコメント
回答 (1 件)
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
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!