2
votes

I have a cube m by n by k which means i have k matrices m by n. I want to reshape it into one big matrix for example p row and q column (consider each m by n matrix as an element).
How can i do that? Can i use reshape function? for example these matrices when put together form a cube:

1 1 , 2 2 , 3 3 , ... , 16 16
1 1   2 2   3 3         16 16

in the above example, k=16, m=n=2.
i want to reshape them like this:

1 1 5 5 9  9  13 13
1 1 5 5 9  9  13 13
2 2 6 6 10 10 14 14
2 2 6 6 10 10 14 14
3 3 7 7 11 11 15 15
3 3 7 7 11 11 15 15
4 4 8 8 12 12 16 16
4 4 8 8 12 12 16 16
1
Please explain what you mean with "k matrices m by n"? A cell of matrices?Daniel
no , they are not cell arrays, as i explained above, they are some smaller matrices which are put together.user3482383
Which is a m by k*n matrix?Daniel
see the example, i have 16 matrices which has 2 rows and 2 columns, as for example [1 1;1 1] or [2 2;2 2] and so on. these are put together to form a cube 2 by 2 by 16. now i want to reshape this cube as i shown in the questionuser3482383

1 Answers

2
votes

Assuming your input is a n by n by k*k matrix, you can achieve the desired input using:

n=2
k=4
reshape(permute(reshape(M,n,n,k,k),[1,3,2,4]),n*k,n*k);

The inner reshape splits into n by n by k by k, which directly represents the blocks.

The permute swaps the dimensions to let a reshape(...,n*k,n*k) produce the intended result.