how in matrix insert other matrix

19 vues (au cours des 30 derniers jours)
Modestas Sekreckis
Modestas Sekreckis le 22 Mai 2011
hi how in matrix insert other matrix? for example I have:
A=repmat(2, [6 6]);
B=repmat(1, [4 4]);
How I can insert B to A and get it:
A=
2 2 2 2 2 2
2 1 1 1 1 2
2 1 1 1 1 2
2 1 1 1 1 2
2 1 1 1 1 2
2 2 2 2 2 2

Réponse acceptée

Razvan
Razvan le 22 Mai 2011
Try
[r,c]=size(B);
xpos=2;ypos=2;
A(xpos:xpos+r-1,ypos:ypos+c-1)=B;
, where xpos and ypos are the positions where you want to insert matrix B.
  4 commentaires
Modestas Sekreckis
Modestas Sekreckis le 22 Mai 2011
but I forgot to say one small detail, I use a 3D matrix in a real program. How then does it work?
Razvan
Razvan le 22 Mai 2011
[x,y,z]=ind2sub(size(A),find(A==1));

Connectez-vous pour commenter.

Plus de réponses (1)

Ben Mitch
Ben Mitch le 22 Mai 2011
A(2:5,2:5) = B;

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by