MATLAB: Moving in the matrix

moving inside matrix

Imagine I have a 4×4 chess board. How can I define the movements of the knight in this board?

Best Answer

(I,J) ->
(I-1,J-2)
(I-1,J+2)
(I+1,J-2)
(I+1,J+2)
(I-2,J-1)
(I-2,J+1)
(I+2,J-1)
(I+2,J+1)
and then filter out the ones that went out of bounds.