How to insert a matrix into another matrix
21 views (last 30 days)
Show older comments
I have a vector of a length up to 2500. How do I reshape this vector of any size up to 50x50 (For example if I don't have 2500 elements, and only have 625, how would I reshape that into a 25x25) and then insert it into a specific point on a 256x256 matrix.
I basically need to insert a smaller matrix into a larger one at a specific point. I am thinking I need to use a for loop.
1 Comment
David Hill
on 20 Apr 2020
If you only have 625 elements, you cannot get a 2500 element matrix. You would have to pad with nan's or zeros or something. Additionally, you did not describe how you wanted the element arraigned in the 50x50 matrix. Inserting a 50x50 matrix into an existing 256x256 matrix is not hard. If m is the 50x50 matrix and M is the 256x256 matrix, then:
M(a:a+49,b:b+49)=m;
Answers (0)
See Also
Categories
Find more on Creating and Concatenating 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!