There are two vectors:
$\boldsymbol{\hat{y}} = (\hat{y_1}, \hat{y_2}, \dots, \hat{y_n})$
$\boldsymbol{{y}} = ({y_1}, {y_2}, \dots, {y_n})$
The vectors $\boldsymbol{\hat{y}}$ and $\boldsymbol{{y}}$ have some matches, but also some values that do not match. From these vectors I would like to create a matrix, which contains like the identity matrix in the diagonal ones, but only if the values match, otherwise zero.
For example:
$\boldsymbol{\hat{y}} = (1.0, 2.0, 3.0, 4.0)$
$\boldsymbol{{y}} = (1.0, 2.2, 3.0, 4.0)$
From these vectors results:
$$ M= \left(\begin{matrix}1&0&0&0\\0&0&0&0\\0&0&1&0\\0&0&0&1\end{matrix}\right)$$
Is there a way to describe the definition of $M$ mathematically?
is a very mathematical description. Don't confuse lack of formulas for lack of mathematics. Personally, I would maybe write it a little differently, but that's mostly just to remove any potential for misinterpretation. For instance, saying that the matrix is diagonal, and explicitly stating that the non-zero entries are $1$ is a bit clearer than saying "contains like the identity matrix". At least to people who are used to reading mathematical texts.
Here is my suggestion:
Alternately, if you really want some formulas, one can use matrix algebra to say