How can I add clips above matrix?

If you are ready to use TikZ, you can take a look at this question two level matrix

or you can look at the following code:

\documentclass{mwrep}

\usepackage{amsmath}

\usepackage{tikz}
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,baseline] \node [anchor=base] (#1) {$#2$};}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

\begin{equation}
\bar{P}=
\bordermatrix{ \mathrm{state} &   \tikzmark{left}{1} &   \tikzmark{right}{2}  \cr
                             1 & 0.3 & 0.1  \cr
                             2 & 0.3 & 0.2}
\end{equation}
\tikz[overlay,remember picture]{\draw[decoration=brace,decorate,blue] (left.north west) -- (right.north east) node[midway,above=3pt] {$s_1$};}
\end{document}

The result is

enter image description here


enter image description here

\documentclass{mwrep}
\usepackage{kbordermatrix}
\usepackage{amsmath}
\makeatletter
\def\hmmA{\noalign{\global\let\@kbrowstyle\scriptstyle}}
\def\hmmB{\noalign{\kern.2ex\global\let\@kbrowstyle\relax}}
\setlength{\kbrowsep}{20pt}
\makeatother
\begin{document}



\begin{equation}
\bar{P}=
\kbordermatrix{
  &\multispan3\hfill$\scriptstyle S_1$\hfill&
   \multispan2\hfill$\scriptstyle S_2$\hfill&
  & \\
  \noalign{\kern-\kbrowsep\kern-.2ex}
  &\multispan3\quad\downbracefill\quad&
   \multispan2\quad\downbracefill\quad&  & \\
\hmmA
\mathrm{state} &   1 &   2 &   4 &   3 &   6 &   5 &   7 \\
\hmmB
                             1 & 0.3 & 0.1 & 0.6 & 0.0 & 0.0 & 0.0 & 0.0 \\
                             2 & 0.2 & 0.1 & 0.7 & 0.0 & 0.0 & 0.0 & 0.0 \\
                             4 & 0.3 & 0.4 & 0.3 & 0.0 & 0.0 & 0.0 & 0.0 \\
                             3 & 0.0 & 0.0 & 0.0 & 0.2 & 0.8 & 0.0 & 0.0 \\
                             6 & 0.0 & 0.0 & 0.0 & 0.3 & 0.7 & 0.0 & 0.0 \\
                             5 & 0.0 & 0.4 & 0.1 & 0.0 & 0.0 & 0.2 & 0.3 \\
                             7 & 0.0 & 0.0 & 0.1 & 0.0 & 0.3 & 0.1 & 0.5}
\end{equation}
\end{document}

As noted in the comments the space adjustments used here don't automatically adjust to changes in baseline stretch. The following modification addresses that, the two additional omit in the rows adding the over-braces, stop LaTeX spacing these lines to the baseline spacing, and as that is then a little too tight, a small vertical kern is added (in place of the negative kern in the version above)

\kbordermatrix{
\omit  &\multispan3\hfill$\scriptstyle S_1$\hfill&
   \multispan2\hfill$\scriptstyle S_2$\hfill&
  & \\
  \noalign{\kern-\kbrowsep\kern1ex}
\omit  &\multispan3\quad\downbracefill\quad&
   \multispan2 \quad\downbracefill\quad&  & \\
\hmmA