[Tex/LaTex] Underbrace/underset multiple elements in a row of array/matrix

alignarraysequationsmatricesunderbrace

I want to indicate with underbraces that in a matrix after an element H_1 there follow K zeros.

\begin{equation*}
P_1 = \begin{bmatrix}
H1,  & \underbrace{0, & 0, & ..., &0, }_{K-times} &H2, &0,  &0, & ..., &0 
\end{bmatrix}
\end{equation*}

But I get an error. If I do this without including the &-symbols it works, but for some purpose I would like to keep the &-symbols. Can I do this somehow while still using the &-operators?

Best Answer

Just underbrace a matrix without delimiters nested inside the pmatrix. I adjusted the spacing of the cdots:

    \documentclass{article}
    \usepackage{mathtools}

    \begin{document}

    \begin{equation*}
    P_1 = \begin{bmatrix}
    H1, & \smash[b]{\underbrace{\begin{matrix}0, & 0, & \mkern-11mu\cdots , & 0,\end{matrix}}_{K\text{ times}}} &H2, &0, &0, & \mkern-11mu\cdots , &0
    \end{bmatrix}
    \end{equation*}

    \end{document} 

enter image description here