如何用圆圈和箭头注释矩阵

如何用圆圈和箭头注释矩阵

我需要使用 tex 生成以下矩阵。我该怎么做?

在此处输入图片描述

在此处输入图片描述

答案1

我认为这里有很多类似的帖子,但只是为了好玩,我建议使用 TikZ 矩阵的解决方案。

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{matrix,fit}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.pathreplacing}

\tikzset{
    mymatr/.style={    
        matrix of math nodes, 
        minimum size=16pt,
        row sep=2pt,
        column sep=2pt,
        left delimiter={[},
        right delimiter={]}, 
        inner xsep=0pt
        },
    mynode/.style={    
        draw, 
        rounded corners=9,
        inner xsep=1pt
        },
    myarrow/.style={    
        draw, 
        -Triangle
        },
    }
\begin{document}
\noindent Matrix:
\[
\underset{m \times l}{\text{M}}=
\begin{tikzpicture}[baseline=(m.center)]
\matrix[mymatr] (m) {
    4 & 1 & 5 & 11 \\ 
    3 & 2 & 7 & 9 \\ 
    2 & 3 & 9 & 7 \\ 
    1 & 4 & 11 & 5 \\
    };
\node[mynode, fit=(m-1-1)(m-4-1)] (firstcol) {};    
\node[mynode, fit=(m-1-4)(m-4-4)] (lastcol) {};    
\node[above =1pt of firstcol] {$m_1$};
\node[above =1pt of lastcol] {$m_l$};
\draw [decorate,decoration={brace,amplitude=8pt,raise=9pt}]
(m-1-4.north east) -- (m-4-4.south east) node [midway,xshift=20pt, anchor=183] {$m$ features};
\end{tikzpicture}
\]
Column vector:
\[
\text{A}=
\begin{tikzpicture}[baseline]
\matrix[mymatr] (v) {
    |[draw, circle]|1 \\ 
    2 \\ 
    3 \\ 
    |[draw, circle]|4 \\
    };
\node[right = of v-1-1, text width=7cm] (firstcomm) {contribution of the first data sample in sparse coding etc.};
\node[right = of v-4-1, text depth=2pt] (secondcomm) {contribution of the $n$th data};
\draw[myarrow] (v-1-1) -- (firstcomm);
\draw[myarrow] (v-4-1) -- (secondcomm);
\end{tikzpicture}
\]
\end{document}

在此处输入图片描述

相关内容