Info

# Index in position 1 is invalid. Array indices must be positive integers or logical values.

2 views (last 30 days)
GHADAH AL-OBAIDI on 18 Apr 2021
Closed: Stephen23 on 27 Apr 2021
I am getting the following error: Index in position 1 is invalid. Array indices must be positive integers or logical values.
Can anybody tell me how can I fix it?
The error in this line:
while m(xm,ym)==0
And my code is:
close all
clear all
clc
xm=-13; ym=-13; th=pi/2;
r=rr; %vector
u=Control();
n=4; %Number of sensors
dT=0.4;
x=-13; y=-13;
for t=1:size(u,1)
v=u(1,t);
if u(2,t)~=0
w=u(2,t);
else
w=100*eps; % 100*eps because eps alone is too small, so causes division by zero problem
end
subplot(1,2,1);
m=Map();
x=x-v/w*sin(th)+v/w*sin(th+w*dT);%state update
y=y+v/w*cos(th)-v/w*cos(th+w*dT);%state update
th=th+w*dT;%state update
for k=0:n-1
th=th+2*pi*k/n;
while m(xm,ym)==0 %if the location not occupied
xm=xm+r*cos(th); %corridnates(x,y) for the robot location
ym=ym+r*sin(th); %r is length(r)
r=rr+0.05;
if m(xm,ym)~=0 %if the location occupied
subplot(1,2,2);
mesh(xm,ym,m); view(0, 90); axis image; hold on;
plot(xm,ym,'b.');
end
end
end
end
Paul Hoffrichter on 27 Apr 2021

Paul Hoffrichter on 19 Apr 2021
Would be very useful if you are able to post a minimal program exhibiting the error that we could run. In the debugger, set the Run button to "Pause on Error". When the program breaks at the error, check that xm and ym are scalars, and check that they are both greater than 0.