Vertical bracket alongside two matrices

matrices

How can I draw a curly bracket on the right side of these two vertically stacked matrices?

enter image description here

Here's the MWE for the matrices:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\begin{document}
$$
X = \begin{bmatrix}
x & \cdots & x\\
\vdots & \ddots & \vdots\\
x & \cdots & x
\end{bmatrix}
$$
$$
Y = \begin{bmatrix}
y & \cdots & y\\
\vdots & \ddots & \vdots\\
y & \cdots & y
\end{bmatrix}
$$
\end{document}

Best Answer

enter image description here

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\[
\left.
\begin{aligned}
X &= \begin{bmatrix}
x & \cdots & x\\
\vdots & \ddots & \vdots\\
x & \cdots & x
\end{bmatrix}
\\
Y &= \begin{bmatrix}
y & \cdots & y\\
\vdots & \ddots & \vdots\\
y & \cdots & y
\end{bmatrix}
\end{aligned}x
\right\}Z
\]
\end{document}