Borrar filtros
Borrar filtros

Can somebody explain this function?

1 visualización (últimos 30 días)
passioncoding
passioncoding el 31 de Ag. de 2018
Respondida: Walter Roberson el 31 de Ag. de 2018
function feasible=feasiblePoint(point,map)
feasible=true;
% check if collission-free spot and inside maps
if ~(point(1)>=1 && point(1)<=size(map,1) && point(2)>=1 && point(2)<=size(map,2) && map(point(1),point(2))==1)
feasible=false;
end
  2 comentarios
Stephen23
Stephen23 el 31 de Ag. de 2018
"Can somebody explain this function?"
Its author, and the code comments that they should have written.
passioncoding
passioncoding el 31 de Ag. de 2018
they are not written

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 31 de Ag. de 2018
point(1) is intended to be a row number in the variable map, and point(2) is intended to be a column number. The code checks to be sure that the row passed is at least 1 and is at most the number of rows in the map array, and that the column passed is at least 1 and is at most the number of columns in the map array, and that the entry at that location in the map array is 1. All of those have to be true for the part inside the () of the if to be considered true. Then the ~ takes the logical negation of that. Therefore the if body will execute if the row number is not in range or the column number is not in range or the value at the location is not 1.
The code could have been written a clearer way:
function feasible=feasiblePoint(point,map)
% check if collission-free spot and inside maps
feasible = (point(1)>=1 && point(1)<=size(map,1) && point(2)>=1 && point(2)<=size(map,2) && map(point(1),point(2))==1);

Más respuestas (0)

Categorías

Más información sobre Statistics and Machine Learning Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by