Text above matrices

The easiest way is to use array:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\begin{array}{ccc}
& & \text{error} \\
& \text{$M$ components} & \text{detection} \\
\text{$N$ spectra} &
\begin{bmatrix}
    a_{11} & a_{12} & \cdots & a_{1M} \\
    a_{21} & a_{22} & \cdots & a_{2M} \\
    \vdots & \vdots & \ddots & \vdots \\
    a_{N1} & a_{N2} & \cdots & a_{NM}
\end{bmatrix} &
\begin{bmatrix}
    e_1 \\
    e_2 \\
    \vdots \\
    e_N
\end{bmatrix}
\end{array}
\]
\end{document}

enter image description here


Try this with stackrel and mbox's

\[
  N\textrm{ spectra}
  \stackrel{\mbox{$M$ components}}{%
    \begin{bmatrix}
    a_{11} & a_{12} & \cdots & a_{1M} \\
    a_{21} & a_{22} & \cdots & a_{2M} \\
    \vdots & \vdots & \ddots & \vdots \\
    a_{N1} & a_{N2} & \cdots & a_{NM}
    \end{bmatrix}%
  }\ \quad
  \stackrel{\stackrel{\mbox{error}}{\mbox{detection}}}{%
    \begin{bmatrix}
    e_1 \\
    e_2 \\
    \vdots \\
    e_N
    \end{bmatrix}%
   }
\]

enter image description here


text where above the matrix? If you want a kind of heading above each column, then probably \bordermatrix is your friend, a plain TeX command but usable in LaTeX.

If you want a single item over the whole matrix, then any latex stacking construct would do the job, stackrel or a second single column array environment with your bmatrix on the second row or....

update: sorry I see you want this second form, didn't notice the image link originally.

so....

\[
  N\textrm{ spectra}
  \begin{smallmatrix} M\textrm{ components}\\\begin{bmatrix}
    a_{11} & a_{12} & \cdots & a_{1M} \\
    a_{21} & a_{22} & \cdots & a_{2M} \\
    \vdots & \vdots & \ddots & \vdots \\
    a_{N1} & a_{N2} & \cdots & a_{NM}
  \end{bmatrix}\end{smallmatrix}\ \quad
  \begin{smallmatrix}
    \textrm{error}\\
    \textrm{detection}\\
   \begin{bmatrix}
    e_1 \\
    e_2 \\
    \vdots \\
    e_N
  \end{bmatrix}\end{smallmatrix}
\]