I have a y of size 5000,1 (matrix), which contains integers between 1 and 10. I want to expand those indices into a 1-of-10 vector. I.e., y contains 1,2,3... and I want it t
Consider the following:
y = randi([1 10],[5 1]); %# vector of 5 numbers in the range [1,10] yy = bsxfun(@eq, y, 1:10)'; %# 1-of-10 encoding
Example:
>> y' ans = 8 8 4 7 2 >> yy yy = 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0