Writing dimension of matrix on its outside corner

I was going to write the dimension of a matrix on its outside corner something like this picture. However, I don't know how to do this. I would be grateful if someone could help me.

You could use the bmatrix environment from the amsmath package, which supports the subscripts

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 2 & 0 & 0\\ 0 & 0 & \ddots & 0\\ 0 & 0 & 0 & n \end{bmatrix}_{n\times n}$
\end{document}


which gives:

I think it might be better extending the ellipsis, to give the sense of the replication for all of the columns:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 2 & 0 & 0\\ \vdots & \vdots & \ddots & \vdots\\ 0 & 0 & 0 & n \end{bmatrix}_{n\times n}$
\end{document}


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

$$\begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 2 & 0 & 0 \\ 0 & 0 & \ddots & 0 \\ 0 & 0 & 0 & n \\ \end{bmatrix}_{n\times n}$$

\end{document}

• @Hamed Do not leave thank you comments; consider upvoting the answers (and, later on accept the one that works for you). Upvoting is the TeX.SE way to say thank you, and accepting answers is good for future reference! – Moriambar May 20 '17 at 12:26