MATLAB: How to add a column between two columns

columnsmatrixvector

I have a matrix 3×3 and a column vector 3×1. I'm trying to add the column vector between the second and third column of the 3×3 matrix.How can i add the column to the matrix?
M1=randi([-10,20],[3,3]); % M1 is 3×3 matrix
r=[5;5;5]; % r is 3×1 vector

Best Answer

out = [M1(:,1:2), r, M1(:,3)];
Related Question