I need to draw a matrix of 25x25 as the one showed below:
Since I'll need to add colors and arrows (it is an schematic diagram), I've decided to use Tikz package to draw it. I've tried in many ways, but the better approach I've found is:
\documentclass[10pt, a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}
\draw (0,0) -- (0, 15);
\draw (0,0) -- (15, 0);
\draw (15,0) -- (15, 15);
\draw (0,15) -- (15, 15);
\foreach \i in {14.4, 13.8, 13.2, 12.6, 12, ..., 0.0}
\ifnum \i<>11.4 {\node at (-\i + 15, 0.6) {0};} \else {\node at (-\i + 15, 0.6) {-1};}\fi;
\end{tikzpicture}
\caption{} \label{}
\end{center}
\end{figure}
\end{document}
which outputs the following matrix:
As you may grasp, my intention was to recreate the matrix row per row, from the lower to the upper part of the canvas, filling each place with its respective number. It is obvious that, in order to do so, is necessary to check the position of \i
in order to place a 0, a 4 or a -1. For example, in the first row, I would need to place a -1 when \i = 13.8
and \i = 11.4
. The problem is that I don't know how to properly use the if sentences, it would be convenient to use nested ifs or several conditions but I could not code that part, all I have is what I post here. Any approach to generate the matrix will be appreciated.
Note: The box has dimensions of 15 per 15 and each node is separated by the distance 0.6, that guarantee that will fit 25x25 elements.
\ifnum
only accepts integers. In your case, it's more like\ifdim \i pt = 11.4 pt ... \else ... \fi
.\ifdim \i<>11.4pt {\node at (-\i + 15, 0.6) {0};} \else {\node at (-\i + 15, 0.6) {-1};}\fi;
I get the following error: Illegal unit of measure (pt inserted). Missing number, treated as zero.\i pt
, because\i
is unitless.