Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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

1 回表示 (過去 30 日間)
GHADAH AL-OBAIDI
GHADAH AL-OBAIDI 2021 年 4 月 18 日
閉鎖済み: Stephen23 2021 年 4 月 27 日
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 件のコメント
GHADAH AL-OBAIDI
GHADAH AL-OBAIDI 2021 年 4 月 18 日
The error in this line:
while m(xm,ym)==0

回答 (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