# Is there a way of choosing the element of a matrix to write again?

Imagine you have a matrix defined as:

\matrix(nums)[matrix of nodes]
{
1 & 2 \\
3 & 4 \\
5 & 6\\
};


and you want to use what's written in node 1-2 and write it in another matrix or someplace along your tikzpicture.

Is there a way to do it?

Is it possible to choose an element of a list using some technique?

You can always define a macro for the desired contents and use whenever you need it:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\newcommand{\myelement}{4}

\begin{document}
Next matrix
\begin{tikzpicture}[baseline]
\matrix(nums)[matrix of nodes, left delimiter=(, right delimiter=)]
{ 1 & 2\\ 3 & \myelement \\ 5 & 6\\};
\end{tikzpicture}
has \myelement{} in position 2,2.

\end{document} If you're mixing math and LaTeX you should consider the sagetex package which utilizes an open source computer algebra system (CAS), Sage. That CAS needs to be installed on your machine or you can access it through a free Sagemath Cloud account. Consider the following code:

\documentclass{article}
\usepackage{sagetex}
\begin{document}
\begin{sagesilent}
M=matrix([[1,2],[3,4],[5,6]])
N = matrix([[M[1,1],0],[0,M[0,1]]])
\end{sagesilent}
For the matrix $M=\sage{M}$ the element in the $(2,1)$ position is  $\sage{M}$.
The dot product of the first two row vectors is
$\sage{M}\cdot \sage{M}+\sage{M}\cdot \sage{M}= \sage{M*M+M*M}$. The $2 \times 2$ diagonal matrix   $N$, with
diagonal elements $(2,2)$ and $(1,2)$ is $\sage{N}$. In that case the matrix $M*N= \sage{M*N}$.
\end{document}


The output is shown below: Notice: Sage refers to matrix elements starting with 0, rather than 1 hence the (1,1) element is in the (0,0) position in the matrix. You can access the math through a \sage{} command. That allows you to pick off elements as you see fit, no macro required. You can also have Sage calculate the matrix multiplication of M*N, which eliminates the possibility of mistakes. Having a CAS do the math eliminates careless mistakes and saves you from having to typeset matrices.