MATLAB: How to reshape a matrix in a specific way

MATLABmatrix reshape

If I have a matrix (A) that is 10×4, how would I reshape this matrix to be a new 5×8 matrix (B) so that the first two rows of A are concatenated to be the first row of B, the 3rd and 4th row of A were the second row of B etc.
Thanks in advance for your help

Best Answer

Just use reshape and transpose (where 8 is the required number of columns):
>> A = rand(10,4); % fake data
>> B = reshape(A.',8,[]).';
and checking:
>> A(1:2,:)
ans =
0.42279 0.17374 0.11111 0.86420
0.25314 0.46765 0.14823 0.10467
>> B(1,:)
ans =
0.42279 0.17374 0.11111 0.86420 0.25314 0.46765 0.14823 0.10467
In your case use (where 25536*72 is the required number of columns):
B = reshape(A.',25536*72,[]).';