You can do this with two reshape and one permute . Let n denote the number of rows in a group:
y = reshape(permute(reshape(x.',size(x,2),n,[]),[2 1 3]),n,[]);
Three-column example, n=2 :
>> x = [1 2 3; 4 5 6; 7 8 9; 10 11 12] x = 1 2 3 4 5 6 7 8 9 10 11 12 >> y = reshape(permute(reshape(x.',size(x,2),n,[]),[2 1 3]),n,[]) y = 1 2 3 7 8 9 4 5 6 10 11 12
source share