I am trying to put an image next to an equation and aligning the subcaptions using subcaptionbox. Unfortunately I am having some issues. See the following MWE:
\begin{figure}[h]
\begin{subfigure}{0.5\textwidth}
\centering
\subcaptionbox{Plot of example character.\label{fig:original_plot}}{\input{Figures/plot.tex}}
\end{subfigure}
~
\begin{subfigure}{0.5\textwidth}
\centering
\subcaptionbox{Format of original data.\label{fig:original_format}}{%
$$
\begin{aligned}
X &= \{\underbrace{\left[\left(x_{1,1},y_{1,1}\right),\dotsc,\left(x_{1,n_1},y_{1,n_1}\right)\right]}_{\text{stroke 1}}, \\
&\qquad \underbrace{\left[\left(x_{2,1},y_{2,1}\right),\dotsc,\left(x_{2,n_2},y_{2,n_2}\right)\right]}_{\text{stroke 2}}, \\
&\qquad \underbrace{\left[\left(x_{3,1},y_{3,1}\right),\dotsc,\left(x_{3,n_3},y_{3,n_3}\right)\right]}_{\text{stroke 3}}\}
\end{aligned}
$$%
}
\end{subfigure}
\caption{.....}
\label{fig:original}
\end{figure}
When compiling, I receive the following error:
! Package amsmath Error: \begin{aligned} allowed only in math mode.
See the amsmath package documentation for explanation.
Type H <return> for immediate help.
...
l.33 ^^I^^I^^I}
Any ideas?

$signs, in this case; never use$$in LaTeX. But what's the purpose of nesting\subcaptionboxinsubfigure? – egreg Jun 12 '17 at 11:04\[...\]preferable to$$...$$? – Werner Jun 12 '17 at 11:12