I am getting this error "Index in position 1 is invalid. Array indices must be positive integers or logical values." Kindly help me clear this.

1 次查看(过去 30 天)
CODE:
Mt=0
m=0
for d=0.1:0.1:10.1
m=m+1
for i=a-2*(N-1)*wd-2*(N-1)*s:2*(wd+s):a-2*(N-N)*wd-2*(N-N)*s
for j=a-2*(N-1)*wd-2*(N-1)*s:2*(wd+s):a-2*(N-N)*wd-2*(N-N)*s
M(i,j)=0
r1=sqrt((x+i).^2+(y+i).^2+d.^2)
r2= sqrt((i-x).^2+(y+i).^2+d.^2)
r3=sqrt((i-x).^2+(y-i).^2+d.^2)
r4= sqrt((x+i).^2+(y-i).^2+d.^2)
C1= i+x
C4= -i-x
C2= i-x
C3= -i+x
d1= y+i
d2= y+i
d3= y-i
d4= y-i
angle=0
% Bz=((((u./(4.*pi)).*((((((-1).^1).*d1)./(r1.*(r1+((-1).^(1+1)).*C1)))-(C1./(r1.*(r1+d1))))+(((((-1).^2).*d2)./(r2.*(r2+(((-1).^(2+1))).*C2)))-(C2./(r2.*(r2+d2))))+(((((-1).^3).*d3)./(r3.*(r3+(((-1).^(3+1))).*C3)))-(C3./(r3.*(r3+d3))))+(((((-1).^4).*d4)./(r4.*(r4+((-1).^(4+1)).*C4)))-(C4./(r4.*(r4+d4)))))))/cos(angle))
M(i,j)=((((u./(4.*pi)).*((((((-1).^1).*d1)./(r1.*(r1+((-1).^(1+1)).*C1)))-(C1./(r1.*(r1+d1))))+(((((-1).^2).*d2)./(r2.*(r2+(((-1).^(2+1))).*C2)))-(C2./(r2.*(r2+d2))))+(((((-1).^3).*d3)./(r3.*(r3+(((-1).^(3+1))).*C3)))-(C3./(r3.*(r3+d3))))+(((((-1).^4).*d4)./(r4.*(r4+((-1).^(4+1)).*C4)))-(C4./(r4.*(r4+d4)))))))/cos(angle))
Mt=Mt+M(i,j)
end
end
Mtl(m)=Mt
end
Mtotal=Mtl(m)*10
plot(d,Mtotal,'x')
ERROR:
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in MaloneAkila (line 70)
M(i,j)=0

回答(1 个)

Torsten
Torsten 2019-9-12
i and j are not defined at this line of your code ; they are first introduced one line later.

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by