[Tex/LaTex] Descriptive text around a matrix

matrices

I am trying to write a matrix with a bit of text sidewards and above it in order to explain its meaning.
At the moment, this is my code:

\begin{equation}
 \begin{turn}{90}
 \mbox{\# rows}
 \end{turn}
\stackrel{\mbox{\# columns}}{
\begin{pmatrix}
  1 & 1 & 1 & 0 & 0\\
  0 & 0 & 1 & 0 & 1\\
  0 & 0 & 0 & 0 & 0\\
  1 & 1 & 1 & 0 & 1\\
  1 & 1 & 0 & 0 & 1\\
 \end{pmatrix}
 }
\end{equation}

And this is the result:

enter image description here

However, the text on the left side of the matrix is not correctly centered (it is too high).
How to center the text around the matrix correctly?

Best Answer

It's easier with an array and \rotatebox:

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}

\begin{document}
\begin{equation}
\begin{array}{@{}c@{\hspace{1ex}}c@{}}
 & \text{\# columns} \\[1ex]
\rotatebox[origin=c]{90}{\text{\# rows}} &
\begin{pmatrix}
  1 & 1 & 1 & 0 & 0\\
  0 & 0 & 1 & 0 & 1\\
  0 & 0 & 0 & 0 & 0\\
  1 & 1 & 1 & 0 & 1\\
  1 & 1 & 0 & 0 & 1\\
 \end{pmatrix}
\end{array}
\end{equation}
\end{document}

enter image description here