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
Another way is to use eye and create a logical matrix that is n x n long, then use the indices to index into the rows of this matrix:
eye
n x n
n = 10; ind = [2 5]; E = eye(n,n) == 1; out = E(ind, :);
We get:
>> out out = 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0