Reshaping 4d array into 2d matrix with a specific pattern

Hello, can someone please help in reshaping/permuting an array?
Say I have a 4d array called tempC, indexed by (n, j, i, k), in which n and i have dimension 3, j and k have dimension 2.
I want to reshape this into a square matrix C that is N*J by I*K, or 6 x 6
The reshaping pattern should be like this:
1111 1112 1121 1122 1131 1132
1211 1212 1221 1222 1231 1232
2111 2112 2121 2122 2131 2132
2211 2212 2221 2222 2231 2232
3111 3112 3121 3122 3131 3132
3211 3212 3221 3222 3231 3232
Intuitively, n-j pairs correspond to rows, i-k pairs correspond to columns. We go through all j's for a given n first, likewise for all k's for a given i.
I am trying so many combinations with permute, and none seem to work...
How would I make this work?

 Respuesta aceptada

Matt J
Matt J el 14 de Oct. de 2023
Editada: Matt J el 14 de Oct. de 2023
reshape( permute(tempC,[2,1,4,3]) ,[N*J, I*K] );

2 comentarios

thanks, it worked! Could you please clarify the reasoning for this?
In your description, j is rastering faster than n. So they must be interchanged. Likewise for k and i.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 13 de Oct. de 2023

Comentada:

el 14 de Oct. de 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by