Problem 1972. Convert matrix to 3D array of triangular matrices
Given a 2D numeric array x in which each column represents the vectorized form of an upper triangular matrix, return a 3D array y containing the concatenated triangular matrices.
- If the size of the input matrix x is MxN, then the size of the output matrix y is PxPxN, where M = sum(1:P)
- You may assume that P<=100
Example
If
x = 1 7 13 2 8 14 3 9 15 4 10 16 5 11 17 6 12 18
then
y(:,:,1) = 1 2 4 0 3 5 0 0 6
y(:,:,2) = 7 8 10 0 9 11 0 0 12
y(:,:,3) = 13 14 16 0 15 17 0 0 18
NOTE: If you are wondering why this seems like a strange task, it is inspired by a genotype->phenotype mapping I am doing in a genetic algorithm.
Solution Stats
Problem Comments
Solution Comments
Show commentsGroup

Matrix Manipulation I
- 16 Problems
- 98 Finishers
- Remove the air bubbles
- Remove NaN ?
- N-Dimensional Array Slice
- Back to basics 21 - Matrix replicating
- Back to basics 23 - Triangular matrix
- Make an awesome ramp for a tiny motorcycle stuntman
- Flip the main diagonal of a matrix
- surrounded matrix
- Some Assembly Required
- Set some matrix elements to zero
- Matrix with different incremental runs
- Removing rows from a matrix is easy - but what about inserting rows?
- Rotate input square matrix 90 degrees CCW without rot90
- Permute diagonal and antidiagonal
- Operate on matrices of unequal, yet similar, size
- Reverse the elements of an array
Problem Recent Solvers112
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!