I have managed to create under braces under my matrix and evened out the spaced using \phantom.
However, there are very large spaces between the columns, the dots, and the brackets. It would be great to make everything more compact horizontally, but I have no idea how to do so.
Could someone help?
\newcommand*{\vertbar}{\rule[-1ex]{0.5pt}{2.5ex}}
\newcommand\undermat[2]{% http://tex.stackexchange.com/a/102468/5764
\makebox[0pt][l]{$\smash{\underbrace{\phantom{%
\begin{matrix}#2\end{matrix}}}_{\text{$#1$}}}$}#2}
\begin{align}
\mathbf{W}_{BA} &
\begin{pmatrix}
\vertbar & & \vertbar & & \vertbar & & \vertbar \
\mathbf{x}^B_1 & \dots & \mathbf{x}^B_1 & \dots & \mathbf{x}^B_p & \dots & \mathbf{x}^B_p \
\undermat{k}{\vertbar & & \phantom{--}\vertbar\phantom{--}} & & \undermat{k}{\vertbar & & {\phantom{--}\vertbar\phantom{--}}}
\end{pmatrix}
= \notag \\
& \begin{pmatrix}
\vertbar & & \vertbar & & \vertbar & & \vertbar \
\mathcal{N}(\mathbf{x}^B_1)_1 & \dots & \mathcal{N}(\mathbf{x}^B_1)_k & \dots & \mathcal{N}(\mathbf{x}^B_p)_1 & \dots & \mathcal{N}(\mathbf{x}^B_p)_k \
\undermat{k}{\vertbar & & \phantom{---}\vertbar\phantom{---}} & & \undermat{k}{\vertbar & & {\phantom{---}\vertbar\phantom{---}}}
\end{pmatrix}.
\
\end{align}

