permuteMerge(x, dims)

Permute and merge (reshape) dimensions in 1 function.
Updated 11 Nov 2014

View License

When manipulating multidimensional matrices, there might be situations that requires swapping (permute) and merging dimensions (reshape). This function simplifies the code and performs the swapping and merging in one function call.
y = permuteMerge(x, dims);

x: input matrix
dims: Cell array indicating how dimensions are to be permuted and merged. Each cell defines an output matrix dimension in the order that is supplied. Specify multiple elements in a cell to merge specific input matrix dimensions.

e.g. permuteMerge(x, {[4 3],[1 2]})
- Rearrange 4D matrix dimensions in the order [4 3 1 2] (@permute)
- Merge dimensions [4 3] and [1 2] to form a 2D output matrix.

Cite As

Spencer Chen (2024). permuteMerge(x, dims) (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2013b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Resizing and Reshaping Matrices in Help Center and MATLAB Answers
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes