I have 2 matrices. One all zeroes, one is a vector of numbers. In the first matrix, I want to switch 1 element/row (to the value 1) based on the value in the second matrix (represents the index). For example:
m1=zeros(3);m2=[ 1 3 2 ];result= [1 0 0; 0 0 1; 0 1 0];
Is there a way to vectorize this and thus do this without a for-loop?
result=zeros(3);m2=[ 1 3 2 ];for i = 1:3 result(i,m2(i)) = 1;end
Thanks a lot for your help.
Best Answer