0
votes

I have three matrices called Matrix 1, Matrix 2 and Matrix 3 (all have equal number of rows and columns). I need to combine them into one matrix (NM) but with the columns in a different order, so:

NM column 1 = 1st column of matrix 1
NM column 2 = 1st column of matrix 2
NM column 3 = 1st column of matrix 3
NM column 4 = 2nd column of matrix 1
NM column 5 = 2nd column of matrix 2

and so on...

Can anyone help me?

Thank you.

2

2 Answers

3
votes

I think this should work:

 NM=reshape ([M1; M2; M3], size (M1, 1), []);
2
votes

Easy

M = vertcat(Matrix1, Matrix2, Matrix3);
M = reshape(M, size(Matrix1, 1), []);