MATLAB: Creating matrix outside for loop

for loopmatrix

I need to create a matrix of variables and have the current code below. Is there anyway to do this without a for loop?
x = 0:.1:1;
y = 0:.1:1;
for i = 1:length(x)
for j = 1:length(y)
x2(i,j) = x(i);
y2(i,j) = y(j);
end
end

Best Answer

Try this:
x2 = y'*ones(size(x));
y2 = ones(size(y'))*x;
EDIT
The R2016b multiplication automatically does the expansion. Previous versions would require bsxfun calls:
x2 = bsxfun(@times, y', ones(size(x)));
y2 = bsxfun(@times, ones(size(y')), x);