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));

Answers (1)

KSSV
KSSV on 17 Jun 2020
Edited: KSSV on 17 Jun 2020
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.

This question is closed.

Tags

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!