For loop indexing error

ri = 40.34;
rf = 40;
Em = 3.5e-9;
Ef = 1000e-9;
z = linspace(0,0.34,12);
n=1;
E = zeros(12);
r = zeros(12);
for j = 1:12
r(j)= z(j)+40;
E(j) = Em*(ri/r(j))+(((ri-r(j))/(ri-rf))^(n/2))*(Ef-Em(ri/rf));
end
I'm getting this error
Array indices must be positive
integers or logical values.
Error in interface_modulus
(line 11)
E(j) =
Em*(ri/r(j))+(((ri-r(j))/(ri-rf))^(n/2))*(Ef-Em(ri/rf));

Respuestas (1)

KSSV
KSSV el 17 de Jun. de 2020
Editada: KSSV el 17 de Jun. de 2020

0 votos

ri = 40.34;
rf = 40;
Em = 3.5e-9;
Ef = 1000e-9;
z = linspace(0,0.34,12);
n=1;
E = zeros(12);
r = zeros(12);
for j = 1:12
r(j)= z(j)+40;
E(j) = Em*(ri/r(j))+(((ri-r(j))/(ri-rf))^(n/2))*(Ef-Em*(ri/rf));
end
Type error:
Replaced
Em(ri/rf)
with
Em*(ri/rf)
When you try Em(ri/rf), it will take as index..and the value comes to be fraction. The indices cannot be fraction..so error.

La pregunta está cerrada.

Etiquetas

Preguntada:

el 17 de Jun. de 2020

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by