Q:

Matlab - How to create logical array matrix without looping

I want to do something like the following:
Y = [1; 2; 3];
X = repmat(1:10, 3, 1);
for i=1:3
    X(i,:) = X(i,:) == Y(i);
end

So I end up with 
X =

     1     0     0     0     0     0     0     0     0     0
     0     1     0     0     0     0     0     0     0     0
     0     0     1     0     0     0     0     0     0     0

Is there a way to do this without looping?

A:

If you start from 1:10 vector, using bsxfun:
Y = [1; 2; 3];
X = bsxfun(@eq, Y, 1:10);

Otherwise with repmat:
Y = [1; 2; 3];
X = repmat(1:10, 3, 1);
X = repmat(Y, 1, size(X,2)) == X;

(Or ones as suggested by leo.)

