Text above matrices

I am new to latex and I am trying to create

So far I have been able to create the matrices, like so:

$N\textrm{ 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}\ \quad \begin{bmatrix} e_1 \\ e_2 \\ \vdots \\ e_N \end{bmatrix}$


Does anyone know how can I add text above the matrices?

-

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}% }$


-
Thank you! This is what I was looking for. –  aperez Jan 29 '12 at 13:56
You're welcome. There is probably a better way of doing this, but this was the first thing to come to mind. –  Mark S. Everitt Jan 29 '12 at 14:00

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}


-

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}$

-
For future interest, if your labeling needs become more complicated, there is the qbordermatrix package which is somewhat more flexible than \bordermatrix as you can label rows or columns and put the labels on any of the four sides of the matrix. I have used this a bit, but have just noticed that the delimiters seem to extend somewhat higher above the top row of matrix elements than I would like.
Do you mind adding kbordermatrix to your answer for the sake of completeness? It can be found on this page. And the documentation is on this link –  percusse Jun 18 '12 at 14:13