TITLE: Definition of a matrix by matching two vectors
QUESTION [5 upvotes]: 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?

REPLY [3 votes]: An alternate way is as follows:
Let $\hat y=(\hat y_1,\hat y_2,...,\hat y_n)$ and $ y=( y_1, y_2,..., y_n)$.
Define $M=diag(a_{11}, a_{22},....,a_{nn})$ as 
$a_{ii}=1$  if  $\hat y_i=y_i$ and $a_{ii}=0$, otherwise.