Code covered by the BSD License

Highlights from Flatten Any Mulitdimensional Matrix into a 2-D Matrix!

Be the first to rate this file! 2 Downloads (last 30 days) File Size: 3.02 KB File ID: #37589 Version: 1.0

Flatten Any Mulitdimensional Matrix into a 2-D Matrix!

Darin Koblick (view profile)

Convert any multidimensional matrix into a 2-D Matrix. Then convert it back to its original form.

File Information
Description

Take any N-D matrix in MATLAB and flatten it down into an N x size(ND,dim) 2-D matrix using fDim.m. This is often times necessary when writing complex operations on multidimensional matrices.

It is also desired that after flattening, the dimension that is preserved has the correct sequence. This is especially important for vector processing.

Once flattened, and an operation has been performed on the 2-D matrix, often times the 2-D matrix will need to be converted back to the original multidimensional matrix. This can be performed using eDim.m.

See the multiDimDemo.m for test cases using various matrix sizes and dimensions.

Example:
Given a multidimensional vector:
>> vector_1 = rand(3,3,3,4,5,3);

Flatten it into a 2-D matrix preserving the 3rd dimension which corresponds to the proper xyz order:
>> [vector_1_f, fSeq] = fDim(vector_1,3);

Convert the flattened matrix back to it's original multidimensional form still preserving the proper xyz order:
>> vector_1_e = eDim(vector_1_f,fSeq);

Required Products MATLAB
MATLAB release MATLAB 7.14 (R2012a)