I need to "riffle" two matrices; COLUMNWISE.
Say that we have:
M1 = {{1, 7, 13, 19, 25, 31}, {2, 8, 14, 20, 26, 32}, {3, 9, 15, 21, 27, 33},
{4, 10, 16, 22, 28, 34}, {5, 11, 17, 23, 29, 35}, {6, 12, 18, 24, 30, 36}};
and:
M2 = {{A, G, M}, {B, H, N}, {C, I, O}, {D, J, P}, {E, K, Q}, {F, L, R}};
I need to get a third matrix:
1, A, 7, G, 13, M, 19, 25, 31
2, B, 8, H, 14, N, 20, 26, 32
3, C, 9, I, 15, O, 21, 27, 33
4, D, 10, J, 16, P, 22, 28, 34
5, E, 11, K, 17, Q, 23, 29, 35
6, F, 12, L, 18, R, 24, 30, 36
In general; the two matrices M1
and M2
have the same number of rows.
On the other hand; the second matrix M2
may have fewer columns than the first matrix M1
; (or both matrices could have the same number of columns).
How can I riffle them to get the above third matrix?
Thank you.