MATLAB: Add a column between tow columns

matrix

Hi,
I am newbie with matlab. I have a matrix like:
a = [ 2 5 7 ; 3 6 8]
I would like to add new column between column 1 and 2, So I will have:
a = [2 1 5 7; 3 4 6 8]
Let me ask it more general, I want to add a column between any two columns.
Thanks

Best Answer

Given the array A and the column vector x, let n be the column after which you want to add x into A:
ncol = size(A,2);
cat(2,A(:,1:n),x,A(:,min(n+1,ncol):end))