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

1 visualización (últimos 30 días)
Aimee Jin
Aimee Jin el 16 de Oct. de 2020
Comentada: Aimee Jin el 16 de Oct. de 2020
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;

Respuestas (1)

KSSV
KSSV el 16 de Oct. de 2020
Editada: KSSV el 16 de Oct. de 2020
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

Categorías

Más información sobre Historical Contests en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by