how in matrix insert other matrix

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 日

0 投票

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 日
and how to choose the elements of the matrix A. who =1 and write it in other matrix for example
C=
2 2
2 3
2 4
2 5
3 2
3 3
etc.
Razvan
Razvan 2011 年 5 月 22 日
[row,col] = find(A==1);
will give you the row/column indices of the elements. If you want them in a matrix C, use C=[row,col]; after that
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 日

0 投票

A(2:5,2:5) = B;

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by