Index in position 1 is invalid. Array indices must be positive integers or logical values.
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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;
rr=1; %Robot radius
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
3 Comments
Sargondjani
on 18 Apr 2021
it would help a lot if you tell us in which line the error occurs. And just post the relevant part of your code. You can also add a "dbstop if error' so you can access all variables in memeory at the time the error occurs
GHADAH AL-OBAIDI
on 18 Apr 2021
Paul Hoffrichter
on 27 Apr 2021
Duplicate questions (as of 2021-04-27):
Answers (1)
Paul Hoffrichter
on 19 Apr 2021
0 votes
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.
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!