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
0 1 0 0 0 0 0 0 0 0
Now, I want to vectorize this process for each row. Writing repmat(1:10, 2, 1) == [2 5]' I expect to get
0 1 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0
But instead, this error occurs:
Error using ==
Matrix dimensions must agree.
Can I vectorize this process, or is a for loop the only option?
>> foo = 1:10; >> foo([1,0,1,0,1,0,1,0,1,0]) Subscript indices must either be real positive integers or logicals. >> foo(logical([1,0,1,0,1,0,1,0,1,0])) ans = 1 3 5 7 9