I have a vector of length m with possible values 1-10 for each element. I want a matrix that is m x 10 with ones in columns corresponding to the elements of the vector. Is there a way to vectorize this loop?
for i = 1:m y_big(i,y(i))=1;end
Example:
y = [4, 8, 1]m = size(v, 2)
I want to get:
y_big = [0 0 0 1 0 0 0 0 0 0; 0 0 0 0 0 0 0 1 0 0; 1 0 0 0 0 0 0 0 0 0]
Best Answer