Can somebody explain this function?

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Stephen23
Stephen23 il 31 Ago 2018
"Can somebody explain this function?"
Its author, and the code comments that they should have written.
passioncoding
passioncoding il 31 Ago 2018
they are not written

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 31 Ago 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);

Più risposte (0)

Categorie

Scopri di più su Statistics and Machine Learning Toolbox in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by