  The matrix Fej\'er-Riesz theorem characterizes positive semidefinite matrix
polynomials on the real line $\mathbb{R}$. We extend a characterization to
arbitrary closed semialgebraic sets $K\subseteq \mathbb{R}$ by the use of
matrix preorderings from real algebraic geometry. In the compact case a
denominator-free characterization exists, while in the non-compact case there
are counterexamples. However, there is a weaker characterization with
denominators in the non-compact case. At the end we extend the results to
algebraic curves.
