Can somebody explain this function?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
passioncoding
le 31 Août 2018
Réponse apportée : Walter Roberson
le 31 Août 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 commentaires
Stephen23
le 31 Août 2018
"Can somebody explain this function?"
Its author, and the code comments that they should have written.
Réponse acceptée
Walter Roberson
le 31 Août 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);
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!