MATLAB Answers

0

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.

Asked by Swathi S on 12 Sep 2019
Latest activity Commented on by Swathi S on 13 Sep 2019
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 Comment

Even after initializng M(i,j) after defining i and j, am getting the same error. Kindly guide.

Sign in to comment.

1 Answer

Answer by Torsten
on 12 Sep 2019

i and j are not defined at this line of your code ; they are first introduced one line later.

  2 Comments

You should probably also consider inititalizing your m variable in your second line.
Sir, I have initialized 'm' in my code but did not mentioned here.

Sign in to comment.