Can somebody explain this function?

1 回表示 (過去 30 日間)
passioncoding
passioncoding 2018 年 8 月 31 日
回答済み: Walter Roberson 2018 年 8 月 31 日
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 件のコメント
Stephen23
Stephen23 2018 年 8 月 31 日
"Can somebody explain this function?"
Its author, and the code comments that they should have written.
passioncoding
passioncoding 2018 年 8 月 31 日
they are not written

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2018 年 8 月 31 日
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 件)

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by