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
You can use bsxfun:
bsxfun
>> bsxfun(@eq, 1:10, [2 5].') ans = 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
Note the transpose .' on the second vector; it's important.
.'