Replace matrix entries in Matlab based on their value and their index -


in matlab, want replace entries in matrix values equal row index one, , others zero.

for example

a = [3 1 4      2 2 5      1 3 3]; 

and want have

b = [0 1 0      1 1 0       0 1 1]; 

is there way efficiently?

bit more generic:

matlab before r2016b:

b = bsxfun(@eq, a, (1:size(a,1)).'); 

matlab r2016b , later:

b = ( == (1:size(a,1)).' ); 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -