I want to convert an integer i to a logical vector with an i-th non-zero element. That can de done with 1:10 == 2, which returns
i
1:10 == 2
0
Just another possibility using indexing:
n = 10; ind = [2 5]; x=zeros(numel(ind),n); x(sub2ind([numel(ind),n],1:numel(ind),ind))=1;