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
Of course, that's why they invented sparse matrices:
>> M = sparse(1:length(v),v,ones(length(v),1)) M = (2,1) 1 (3,2) 1 (1,4) 1
which you can convert to a full matrix if you want with full:
>> full(M) ans = 0 0 0 1 1 0 0 0 0 1 0 0