When the matrix library is loaded and the matrix of nodes key is activated, each node can be accessed according to the name-row-column syntax.
In some cases, the arrows are built in the opposite direction of what is requested. To illustrate this, I have colored in red the arrows that are drawn in the opposite direction of what is requested.
I colored the background of the cells from which the arrows start in blue.
Update without shorten <=-3pt,shorten >=-3pt
By default, when cells are placed side by side, the arrows are reversed.
\documentclass[border=10pt,tikz]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (magic) [matrix of nodes]
{
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
};
\draw[thick,blue,->] (magic-1-1) |- (magic-2-3);
\draw[thick,blue,->] (magic-1-1) -- (magic-2-3);
\draw[thick,red,->] (magic-1-1) -- (magic-1-2);
\end{tikzpicture}
\end{document}
\documentclass[border=10pt,tikz]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (magic) [matrix of nodes,
row 1 column 1/.style={nodes={fill=blue!20}},
row 2 column 3/.style={nodes={fill=blue!20}},
row 4 column 1/.style={nodes={fill=blue!20}},
row 1 column 5/.style={nodes={fill=blue!20}},
row 2 column 6/.style={nodes={fill=blue!20}},
row 3 column 5/.style={nodes={fill=blue!20}},
row 4 column 6/.style={nodes={fill=blue!20}},
row 7 column 4/.style={nodes={fill=blue!20}},
row 4 column 4/.style={nodes={fill=blue!20}}]
{
8 & 8 & 8 & 8 & 8 & 8 & 8\
3 & 3 & 5 & 7 & 7 & 6 & 5\
4 & 4 & 9 & 2 & 6 & 5 & 4 \
4 & 4 & 9 & 2 & 5 & 4 & 3 \
8 & 8 & 8 & 8 & 8 & 8 & 8\
3 & 3 & 5 & 7 & 7 & 6 & 5\
4 & 4 & 9 & 2 & 6 & 5 & 4 \
4 & 4 & 9 & 2 & 5 & 4 & 3 \
};
\draw[thick,blue,->,shorten <=-3pt,shorten >=-3pt] (magic-1-1) |- (magic-2-2);
\draw[thick,red,->,shorten <=-3pt,shorten >=-3pt] (magic-1-1) -- (magic-2-2);
\draw[thick,blue,->,shorten <=-3pt,shorten >=-3pt] (magic-1-1) -| (magic-2-2);
\draw[thick,blue,->,shorten <=-3pt,shorten >=-3pt] (magic-4-4) |- (magic-3-3);
\draw[thick,red,->,shorten <=-3pt,shorten >=-3pt] (magic-4-4) -- (magic-3-3);
\draw[thick,blue,->,shorten <=-3pt,shorten >=-3pt] (magic-4-4) -| (magic-3-3);
\draw[thick,red,->,shorten <=-3pt,shorten >=-3pt] (magic-4-1) -- (magic-3-2);
\draw[thick,blue,->,shorten <=-3pt,shorten >=-3pt] (magic-4-1) |- (magic-3-2);
\draw[thick,blue,->,shorten <=-3pt,shorten >=-3pt] (magic-4-1) -| (magic-3-2);
\draw[thick,red,->,shorten <=-3pt,shorten >=-3pt] (magic-2-3) -- (magic-1-4);
\draw[thick,blue,->,shorten <=-3pt,shorten >=-3pt] (magic-2-3) |- (magic-1-4);
\draw[thick,blue,->,shorten <=-3pt,shorten >=-3pt] (magic-2-3) -| (magic-1-4);
\draw[thick,red,->,shorten <=-3pt,shorten >=-3pt] (magic-1-5) -- (magic-2-5);
\draw[thick,red,->,shorten <=-3pt,shorten >=-3pt] (magic-2-6) -- (magic-1-6);
\draw[thick,red,->,shorten <=-3pt,shorten >=-3pt] (magic-3-5) -- (magic-3-6);
\draw[thick,red,->,shorten <=-3pt,shorten >=-3pt] (magic-4-6) -- (magic-4-5);
\draw[thick,blue,->,shorten <=-3pt,shorten >=-3pt] (magic-7-4) -- (magic-6-1);
\draw[thick,blue,->,shorten <=-3pt,shorten >=-3pt] (magic-7-4) -- (magic-6-2);
\draw[thick,red,->,shorten <=-3pt,shorten >=-3pt] (magic-7-4) -- (magic-6-3);
\draw[thick,red,->,shorten <=-3pt,shorten >=-3pt] (magic-7-4) -- (magic-6-4);
\draw[thick,red,->,shorten <=-3pt,shorten >=-3pt] (magic-7-4) -- (magic-6-5);
\draw[thick,blue,->,shorten <=-3pt,shorten >=-3pt] (magic-7-4) -- (magic-6-6);
\draw[thick,blue,->,shorten <=-3pt,shorten >=-3pt] (magic-7-4) -- (magic-6-7);
\draw[thick,blue,->,shorten <=-3pt,shorten >=-3pt] (magic-7-4) -- (magic-8-1);
\draw[thick,blue,->,shorten <=-3pt,shorten >=-3pt] (magic-7-4) -- (magic-8-2);
\draw[thick,red,->,shorten <=-3pt,shorten >=-3pt] (magic-7-4) -- (magic-8-3);
\draw[thick,red,->,shorten <=-3pt,shorten >=-3pt] (magic-7-4) -- (magic-8-4);
\draw[thick,red,->,shorten <=-3pt,shorten >=-3pt] (magic-7-4) -- (magic-8-5);
\draw[thick,blue,->,shorten <=-3pt,shorten >=-3pt] (magic-7-4) -- (magic-8-6);
\draw[thick,blue,->,shorten <=-3pt,shorten >=-3pt] (magic-7-4) -- (magic-8-7);
\end{tikzpicture}
\end{document}





row sep=1em, column sep=1em,then it works. It might be a combination of (1) each box basically touching and (2) you using-3ptand and we are drawing from the edge of the boxes. The negative shorten then ens up sitting on opposite sides of the boxes and the arrow is reversed – daleif Aug 13 '20 at 12:23.center– daleif Aug 13 '20 at 12:26shorten <=-3pt,shorten >=-3ptthen, the arrows are drawn but in the wrong direction. It is then necessary to space the rows and the columns so that it becomes normal again as you did. – AndréC Aug 13 '20 at 12:28bugin the title is not a good idea ;-) – daleif Aug 13 '20 at 12:32outer sep=0ptthen it works. It is seems to be usingouter sepas a limit as to then the switch happens, if inside then it switches – daleif Aug 13 '20 at 13:09matrixlibrary. It can be done with normal nodes. – daleif Aug 13 '20 at 13:11outer sepor so ofcolumn sepandrow sepseems to me to need to be explored further. The ideal would be to find the exact cause so that you can propose a fix in the TikZ repository. – AndréC Aug 13 '20 at 15:00north text,south textnorth east text(there is an anchor calledtextas shown in theshapelibrary). This would allow the arrows to start not from the node boundary, but from the text boundary. – AndréC Aug 14 '20 at 05:53