In MATLAB, I want to replace those entries in a matrix that their values equal to their row index with one, and the others with zero.
For example
A = [3 1 4 2 2 5 1 3 3]; and I want to have
B = [0 1 0 1 1 0 0 1 1]; Is there any way to do so efficiently?