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

回答(1 个)

KSSV
KSSV 2020-6-17
编辑:KSSV 2020-6-17
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.

此问题已关闭。

标签

关闭:

2021-8-20

Community Treasure Hunt

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

Start Hunting!

Translated by