How to insert a matrix into another matrix

18 vues (au cours des 30 derniers jours)
Daniel Coughenour
Daniel Coughenour le 19 Avr 2020
Commenté : David Hill le 20 Avr 2020
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 commentaire
David Hill
David Hill le 20 Avr 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;

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by