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)
feasible = (point(1)>=1 && point(1)<=size(map,1) && point(2)>=1 && point(2)<=size(map,2) && map(point(1),point(2))==1);
2 件のコメント
このコメントへの直接リンク
https://jp.mathworks.com/matlabcentral/answers/416966-can-somebody-explain-this-function#comment_605172
このコメントへの直接リンク
https://jp.mathworks.com/matlabcentral/answers/416966-can-somebody-explain-this-function#comment_605172
このコメントへの直接リンク
https://jp.mathworks.com/matlabcentral/answers/416966-can-somebody-explain-this-function#comment_605175
このコメントへの直接リンク
https://jp.mathworks.com/matlabcentral/answers/416966-can-somebody-explain-this-function#comment_605175
サインインしてコメントする。