[Tex/LaTex] How to place arrows horizontally and vertically beside matrix

arrowsmatrices

I would like to create a matrix with arrows next to it. Say, I created a 10×10 matrix in Latex. Then, I want to put one arrow parallel to the "x-axis" of the matrix and I want to label the arrow, e.g. with "variables". The same for the vertical axis which I want to label, say, "observations".

Is there any way to do this in Latex? Thanks in advance!

Best Answer

Try this. Both arrows should automatically expand base on the size of the matrix. You may want to shorten the horizontal arrow a bit, but it'd be hard to do without manually specifying the width of the matrix through the use of custom spacer such as \hphantom{\hrule{1cm}} replacing the \hphantom part of the code below, unless someone has better idea.

enter image description here

\documentclass{article}
\usepackage{mathtools}
\begin{document}

\newcommand{\mymatrix}[1]{\ensuremath{\left\downarrow\vphantom{#1}\right.\overset{\xrightarrow[\hphantom{#1}]{\text{variables}}}{#1}}}
\begin{equation*}
\text{\tiny observations}\mymatrix{\begin{pmatrix}
        a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\
        a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\
        \vdots  & \vdots  & \ddots & \vdots  \\
        a_{m,1} & a_{m,2} & \cdots & a_{m,n}
        \end{pmatrix}}
\end{equation*}
\end{document}