how in matrix insert other matrix

13 次查看(过去 30 天)
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

采纳的回答

Razvan
Razvan 2011-5-22
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 个评论
Modestas Sekreckis
Modestas Sekreckis 2011-5-22
but I forgot to say one small detail, I use a 3D matrix in a real program. How then does it work?
Razvan
Razvan 2011-5-22
[x,y,z]=ind2sub(size(A),find(A==1));

请先登录,再进行评论。

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by