Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Index in position 1 is invalid. Array indices must be positive integers or logical values.
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
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
Respuestas (1)
  Paul Hoffrichter
 el 19 de Abr. de 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.
0 comentarios
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!