MATLAB: Rearrangement rows of matrices

reshape

Suppose:
A = repmat((1:15)',1,5);
Now I want to rearrange A such that it becomes matrix of size 5 by 15 in following form:
B = [A(1:5,:), A(6:10,:), A(11:15,:)];
The problem is that size of matrix A in my work is too big and its size may change in each iteration. So I can't use a fix command like above to evaluate B. On the other hand, using a for loop is too much time consuming. I tried function "reshape". But, it does not work well.
Is there any function to do this? or how should I call function reshape to get what I want?

Best Answer

A = reshape(A,[5 3 5]);
A = permute(A,[1 3 2]);
A = reshape(A,[5 15]);