  We construct the general solution of the equation
$w_t+\sum\limits_{k=1}^nw_{x_k}\rho^{(k)}(w)=\rho(w)+[w,T\tilde\rho(w)]$, for
the $N\times N$ matrix $w$, where $T$ is any constant diagonal matrix, $n, N
\in \NN_+$ and $\rho^{(k)}, \rho, \tilde\rho: \RR \to \RR$ are arbitrary
analytic functions. Such a solution is based on the observation that, as $w$
evolves according to the above equation, the evolution of its spectrum
decouples, and it is ruled by the scalar analogue of the above equation.
Therefore the eigenvalues of $w$ and suitably normalized eigenvectors are the
$N^2$ Riemann invariants. We also obtain, in the case $\rho=\tilde\rho=0$, a
system of $N^2$ non-differential equations characterizing such a general
solution. We finally discuss reductions of the above matrix equation to systems
of $N$ equations admitting, as Riemann invariants, the eigenvalues of $w$. The
simplest example of such reductions is a particular case of the gas dynamics
equations
