I made some commands to store a matrix and to show the matrix, an element of the matrix, or a submatrix.
The elements of the matrix are saved <matrix name>-<y>-<x>, so you could define further commands with that.
Result

Code
\documentclass{article}
\usepackage{etoolbox}
\usepackage{pgffor}
\usepackage{booktabs}
\def\dmname{}
\newcounter{dmx}
\newcounter{dmy}
\newcommand{\dmlines}[1]{%
\setcounter{dmx}{0}
\forcsvlist{\dmelements}{#1}
\stepcounter{dmy}
}
\newcommand{\dmelements}[1]{%
\csdef{\dmname-\thedmy-\thedmx}{#1}%
\stepcounter{dmx}%
}
\newcommand{\definematrix}[2]{%
% #1 = name
% #2 = matrix
\gdef\dmname{#1}%
\setcounter{dmy}{0}%
\forcsvlist{\dmlines}{#2}%
\csxdef{\dmname-w}{\thedmx}%
\csxdef{\dmname-h}{\thedmy}%
}
\newcommand{\getmatrixelement}[3]{%
% #1 = name
% #2 = y
% #3 = x
\csuse{#1-#2-#3}%
}
\newcommand{\getsubmatrix}[5]{%
% #1 = name
% #2 = y
% #3 = x
% #4 = y2
% #5 = x2
\def\dmtablecontent{}%
\foreach \y in {#2, ..., #4} {%
\foreach \x in {#3, ..., #5} {%
\xappto\dmtablecontent{\csuse{#1-\y-\x}}%
\ifnumless{\x}{#5}{%
\xappto\dmtablecontent{&}%
}{}%
}%
\xappto\dmtablecontent{\}%
}%
%
\begin{tabular}{*{\the\numexpr#5-#3+1\relax}{c}}%
\dmtablecontent%
\end{tabular}%
}
\newcommand{\getmatrixwidth}[1]{%
% #1 = name
\csuse{#1-w}%
}
\newcommand{\getmatrixheight}[1]{%
% #1 = name
\csuse{#1-h}%
}
\newcommand{\getmatrix}[1]{%
% #1 = name
\getsubmatrix{#1}{0}{0}
{\the\numexpr\getmatrixheight{#1}-1\relax}
{\the\numexpr\getmatrixwidth{#1}-1\relax}%
}
\newcommand{\getmatrixwithoutrc}[3]{%
% shows the matrix without the given row and column
% #1 = name
% #2 = row
% #3 = column
\def\dmtablecontent{}%
\def\dmymax{\the\numexpr\getmatrixheight{#1}-1\relax}%
\def\dmxmax{\the\numexpr\getmatrixwidth{#1}-1\relax}%
\foreach \y in {0, ..., \dmymax} {%
\ifnumequal{\y}{#2}{}{%
\foreach \x in {0, ..., \dmxmax} {%
\ifnumequal{\x}{#3}{}{%
\xappto\dmtablecontent{\csuse{#1-\y-\x}}%
\ifnumless{\x}{\dmxmax}{%
\xappto\dmtablecontent{&}%
}{}%
}%
}%
\xappto\dmtablecontent{\}%
}%
}%
%
\begin{tabular}{*{\getmatrixwidth{#1}}{c}}
\dmtablecontent
\end{tabular}
}
\begin{document}
\definematrix{a}{{1, 2}, {3, 4}}
\definematrix{b}{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{ll}
\toprule
\textbf{Result} & \textbf{Command}\
\midrule
& \verb|\definematrix{a}{{1, 2}, {3, 4}}|\
& \verb|\definematrix{b}{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}| \
$\getmatrixheight{a} \times \getmatrixwidth{a}$ &
\verb|$\getmatrixheight{a} \times \getmatrixwidth{a}$|
\
\getmatrix{a} &
\verb|\getmatrix{a}|
\
\getmatrixelement{a}{0}{0} &
\verb|\getmatrixelement{a}{0}{0}|
\
\getmatrixelement{a}{1}{0} &
\verb|\getmatrixelement{a}{1}{0}|
\
\getsubmatrix{a}{0}{1}{1}{1} &
\verb|\getsubmatrix{a}{0}{1}{1}{1}|
\
\getmatrix{b} &
\verb|\getmatrix{b}|
\
\getsubmatrix{b}{1}{1}{2}{2} &
\verb|\getsubmatrix{b}{1}{1}{2}{2}|
\
\getmatrixwithoutrc{b}{1}{1} &
\verb|\getmatrixwithoutrc{b}{1}{1}|
\
\bottomrule
\end{tabular}
\end{document}
\csname foo\i.\j\endcsnamewhich can be manipulated easily. Printing it would be a separate step. – John Kormylo Sep 06 '23 at 03:28etoolbox(combining storing a matrix and building another one), though at the end, they would be pretty similar. Are you okay with a comma-separated list of rows of comma-separated entries per row or do you need the LaTeX-like input with&and\\? – Qrrbrbirlbel Sep 06 '23 at 12:31