I have a m-dimensional vector of integers ranging from 1 to n. These integers are column indexes for m × n matrix.
I want to create a
Or without sparse matrix:
>> M = zeros(max(v),length(v)); >> M(v'+[0:size(M,2)-1]*size(M,1)) = 1; >> M = M' M = 0 0 0 1 1 0 0 0 0 1 0 0
Transposition is used because in matlab arrays are addressed by columns