MATLAB: Creating a matrix from two sets of data

matrixmatrix arraymatrix manipulation

Hello
Lets say, I have a row of numbers :x= [1 2 3 4]. I also have a column of numbers: y= [1;2]
I need to creat another matix from x, y comibation. so x is going to be paired with each y.
c =
1 1
2 1
3 1
4 1
1 2
2 2
3 2
4 2
Thank you !

Best Answer

You can use ndgrid to generate every combination.
[X, Y] =ndgrid(x, y);
out=[X(:) Y(:)];