Asked by samia
on 1 Jun 2011

how can I convert a 6-dimensional matrix into a matrix of dimension 4 then 2

Answer by Jan
on 1 Jun 2011

A 6-dimensional array (a "matrix" has 2 dimensions):

X = rand(2,3,4,5,6,7);

It is impossible to reshape this to the dimensions [4 x 2], which would be a matrix. So actual I believe that RESHAPE will do what you want, but a further explanaiotion of the wanted result is needed.

Sign in to comment.

Answer by Andrei Bobrov
on 1 Jun 2011

A = rand(6,1) % array dimension 6x1

out = reshape(A,4,2);

Jan
on 1 Jun 2011

samia
on 1 Jun 2011

Jan
on 1 Jun 2011

What is "dimension 4"? Please try to use a proper Matlab terminology. See the commands SIZE and NDIMS.

I do not see any way to face the fact, that you do not "want" to use RESHAPE. Either RESHAPE creates the correct results, or you are looking for something else but did not explain it very well -- in both cases "wanting" does not matter.

Sign in to comment.

Answer by Laura Proctor
on 1 Jun 2011

The results below will reshape from a 6D to a 4D array. If you don't want to use reshape, is there something else you have in mind?

A = rand(8,8,3, 3, 32, 32);

B = reshape(A,[],64,8,6);

Jan
on 1 Jun 2011

@Matt: Do you understand how [3 3 3 3 83 83] and "put each 9 block of 8*8" match together?

Matt Fig
on 1 Jun 2011

@Jan: No. I simply don't understand the way samia is doing this. The smallest I for which I can get the code to produce a 6D gr9 is:

I = round(rand(12,12)*200);

which produces a gr9 of size [3 3 3 3 2 2]. This I can actually trace through and look at how the elements of gr9 are taken, but I see no clear patter that I think would extend to I 256-by-256... With the latter I of course there is no chance of tracing through!

samia
on 1 Jun 2011

I know it is not simple to understand! look: after devide A into block of 8*8 you get for example B; size(B) is [8 8 30 30] with last code now you take B and grouped each 9 small block together (small block mean block of 8*8) you gr9 of size= [8 8 3 3 30 30 ] you can test this result.

my problem is in the reverse path

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 1 Comment

## Jan (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/8587-convert-matrix#comment_18606

Sign in to comment.