Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
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

답변 (1개)

Paul Hoffrichter
Paul Hoffrichter 2021년 4월 19일
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.

Community Treasure Hunt

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

Start Hunting!

Translated by