MATLAB: Combining the matrix’ values

combiningmatrix

is there any predefined function let us to combine the values in a matrix example: let A the original matrix
if true
A= 1 2
4 5
7 8
end
the result that i'm loking for is
if true
C= 1 1 1 1 2 2 2 2
4 4 5 5 4 4 5 5
7 8 7 8 7 8 7 8
end

Best Answer

C = allcomb(A(1,:),A(:,2),A(:,3))'
You can find allcomb (by Jos) on the FEX:
Or more generally,
B = mat2cell(A,ones(1,size(A,1)),size(A,2));
C = allcomb(B{:})';