How to stack k copies of a matrix
3 views (last 30 days)
Show older comments
I would like to write a function which takes an integer k > 0 as input and a m by n matrix A as input and produces a m by n by k matrix such that each m by n slice is equal to A; this operation is sometimes colloquially referred to as "stacking" copies of A. It is easy to do this using for loops; we first initialize a m by n by k matrix of zeros and then iterate over the last dimension, setting each slice to be equal to A. Is there an easier way? It seems like Matlab should have built-in functions for this.
0 Comments
Answers (2)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!