check array for zeros using for increment
1 次查看(过去 30 天)
显示 更早的评论
I am trying to create a game of battleship, given an array populated by zeros, when a value is changed (places a ship), I want to check if a ship is already there array(row, col) ~= 0. but this only works when the origin is populated. I can't seem to change the code in a regard where it checks each element startRow to endRow. is there a better way to implement this check?
%input is direction, row, col
check = true
switch direction
case 0 %n
startRow = row;
endRow = startRow - (shipLength - 1);
for i = endRow:startRow
if array(row,col) ~= 0
check = false;
end
end
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!