MATLAB: Concantenating arrays within a 4D matrix

4d matrixconcatenateMATLABmatrix manipulationreshape

Hi All I hope you are well,
I have a 4D single matrix of dimensions 40 x 1498 x 1 x 575 . Where rows = frequency bands, columns= time, each cell holds a complex number and 575 is the number of spectrograms/files ( this is a spectrogram training set for a neural network). My hope is to concantenate the number of files into one long sequence and create a vector of dimensions (575*1498) x 40 x 1.
I have taken a much simpler example to test the reshape and permute functions,
For example:
A = [ 1 2 3; 4 5 6; 7 8 9; 10 11 12];
A(:,:,1,2) = [9 7 8 ;5 2 3 ;5 8 5 ;1 6 9 ];
size(A)
B = permute(A,[2,1,4,3])
size(B)
Which has given me matrix B (which is the intermediate to what I want)
B = [ 1 4 7 10; 2 5 8 11; 3 6 9 12]
B(:,:,1,2) = [9 5 5 1; 7 2 8 6; 8 3 5 9]
I would like to end up with Matrix C
C = [ 1 4 7 10; 2 5 8 11; 3 6 9 12; 9 5 5 1; 7 2 8 6; 8 3 5 9]
Is there anyway to achieve what I am looking for, or am I missing something fundamental?
Thank you!

Best Answer

From the inital part of your question description it seems that you want to change order of matrix dimensions. See permute()
A % matrix of size 40 x 1498 x 1 x 575
B = permute(A, [4 2 1 3]) % B is matrix of demension 575 * 1498 x 40