# How to circle together certain entries of a matrix?

I am looking for a way to circle together the red entries of the following matrix:

$$\begin{matrix} \textcolor{blue}{[0,1]} & \times & \textcolor{blue}{[0,1]} & \times & \textcolor{blue}{[0,1]} & \times & \textcolor{blue}{[0,1]} & \times & \textcolor{blue}{[0,1]} & \times & \cdots & \times & \textcolor{blue}{[0,1]} & \times & \textcolor{blue}{[0,1]} & \times & \textcolor{blue}{[0,1]} \\ \textcolor{blue}{[2,3]} & \times & \textbf{\textcolor{red}{[0,1]}} & \times & \textbf{\textcolor{red}{[0,1]}} & \times & \textbf{\textcolor{red}{[0,1]}} & \times & \textbf{\textcolor{red}{[0,1]}} & \times & \cdots & \times & \textbf{\textcolor{red}{[0,1]}} & \times & \textbf{\textcolor{red}{[0,1]}} & \times & \textbf{\textcolor{red}{[0,1]}} \\ \textbf{\textcolor{red}{[1,2]}} & \times & \textcolor{blue}{[2,3]} & \times & [0,1] & \times & [0,1] & \times & [0,1] & \times & \cdots & \times & [0,1] & \times & [0,1] & \times & \textbf{\textcolor{red}{[0,1]}} \\ [1,2] & \times & [1,2] & \times & \textcolor{blue}{[2,3]} & \times & [0,1] & \times & [0,1] & \times & \cdots & \times & [0,1] & \times & [0,1] & \times & [0,1] \\ [1,2] & \times & [1,2] & \times & [1,2] & \times & \textcolor{blue}{[2,3]} & \times & [0,1] & \times & \cdots & \times & [0,1] & \times & [0,1] & \times & [0,1]\\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ [1,2] & \times & [1,2] & \times & [1,2] & \times & [1,2] & \times & [1,2] & \times & \cdots & \times & [1,2] & \times & \textcolor{blue}{[2,3]} & \times & [0,1]\\ [1,2] & \times & [1,2] & \times & [1,2] & \times & [1,2] & \times & [1,2] & \times & \cdots & \times & [1,2] & \times & [1,2] & \times & \textcolor{blue}{[2,3]}\\ \end{matrix}.$$


Actually, I need many circles like this: all entries before the blue entry in a line should be circled with all entries after the blue entry in the previous line. A simple thin circle would do the job. Is there a standard way of doing this?

Thanks!

PS: A picture of a possible output (simplified):

Perhaps something like this would work?

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc,matrix,backgrounds}

\pgfdeclarelayer{overlay}
\pgfsetlayers{overlay,background,main}

\tikzset{circle/.style = {rounded corners,line width=1bp,color=#1}}%

\begin{document}

$\left[ \begin{tikzpicture}[baseline=-\the\dimexpr\fontdimen22\textfont2\relax] \matrix (m)[matrix of math nodes] { A & B & C & D \\ E & F & G & H \\ I & J & K & L \\ M & N & O & P\\ }; \begin{pgfonlayer}{overlay} \draw[circle=blue] (m-2-2.north east) -- (m-2-3.north east) -- (m-2-3.south east) -- (m-3-4.north east) -- (m-3-4.south east) -- (m-3-4.south west) -- (m-2-3.south east) -- (m-2-2.south west) -- (m-2-2.north west) -- (m-2-2.north east); \end{pgfonlayer} \end{tikzpicture} \right]$
\end{document}


Another possibility with pst-node. I slightly simplified your code:

    \documentclass[svgnames]{article}
\usepackage{array, mathtools}
\usepackage{pst-node, auto-pst-pdf}

\begin{document}

$\arraycolsep=1pt \setlength{\extrarowheight}{3pt} \begin{postscript \begin{array}{*{17}{c}} \color{blue} [0,1] & \times & \color{blue} [0,1] & \times & \color{blue} [0,1] & \times & \color{blue} [0,1] & \times & \color{blue} [0,1] & \times & \cdots & \times & \color{blue} [0,1] & \times & \color{blue} [0,1] & \times & \color{blue} [0,1] \\ \color{blue} [2,3] & \times & \pnode[-0.3ex,2.4ex]{C} \color{red}\mathbf{[0,1]} & \times & \color{red}\mathbf{[0,1]} & \times & \color{red} \mathbf{[0,1]} & \times & \color{red} \mathbf{[0,1]} & \times & \cdots & \times & \color{red} \mathbf{[0,1]} & \times & \color{red} \mathbf{[0,1]} & \times \pnode[0.2ex,-1ex]{G} & \color{red} \mathbf{[0,1]} \pnode[0.4ex,2.4ex]{D}\\ \pnode[-0.4ex,2.4ex]{A}\pnode[-0.4ex,-1.2ex]{L} \color{red} \mathbf{[0,1]}\pnode[0.4ex,2.4ex]{H}\pnode[0.4ex,-1.2ex]{K} &\times \pnode[0.2ex,2.4ex]{B} & \color{blue} [2,3] & \times & [0,1] & \times & [0,1] & \times & [0,1] & \times & \cdots & \times & [0,1] & \times & [0,1] & \times \pnode[0.2ex,-1ex]{F} & \color{red} \mathbf{[0,1]} \pnode[0.4ex,-1ex]{E} \\{} [1,2] & \times & [1,2] & \times & \color{blue} [2,3] & \times & [0,1] & \times & [0,1] & \times & \cdots & \times & [0,1] & \times & [0,1] & \times & [0,1] \\{} [1,2] & \times & [1,2] & \times & [1,2] & \times & \color{blue} [2,3] & \times & [0,1] & \times & \cdots & \times & [0,1] & \times & [0,1] & \times & [0,1]\\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\{} [1,2] & \times & [1,2] & \times & [1,2] & \times & [1,2] & \times & [1,2] & \times & \cdots & \times & [1,2] & \times & \color{blue} [2,3] & \times & [0,1]\\{} [1,2] & \times & [1,2] & \times & [1,2] & \times & [1,2] & \times & [1,2] & \times & \cdots & \times & [1,2] & \times & [1,2] & \times & \color{blue} [2,3]\\ \end{array}. %% \psline[linecolor=Crimson!60, linejoin=1,linearc=2pt](A)(B)(C)(D)(E)(F)(G)(H)(K)(L)(A) \end{postscript}$%

\end{document}