Reputation: 3
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.
Upvotes: 0
Views: 40
Reputation: 3071
I think this should work:
NM=reshape ([M1; M2; M3], size (M1, 1), []);
Upvotes: 3
Reputation: 2714
Easy
M = vertcat(Matrix1, Matrix2, Matrix3);
M = reshape(M, size(Matrix1, 1), []);
Upvotes: 2