MATLAB: Expanding matrix

matrix manipulation

Hi all
I want to expand matrix.for example if x=[x1;x2] then the new matrix will be:
xx = [x1 x1 x1;x1 x1 x2;x1 x2 x1;x1 x2 x2;x2 x1 x1;x2 x1 x2;x2 x2 x1;x2 x2 x2]
How can I do that

Best Answer

[j k i]=meshgrid([x1,x2]);
xx = [i(:) j(:) k(:)];
Related Question