Adding smaller matrices into a bigger matrix

How to add two small matrices a(2X2) and b(2X2) into a large matrix of K(3X3) such that matrix a occupies K(1:2,1:2) and matrix b occupies K(2:3,2:3)).
Also at the intersection of two matrices i.e., K(2,2) = a(2,2)+b(1,1)
K = (a(1,1) a(1,2) 0
a(2,1) a(2,2)+b(1,1) b(1,2)
0 b(2,1) b(2,2))];

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 3 日

1 投票

a = [1 2;
3 4];
b = [5 6;
7 8];
K = zeros(3,3);
K(1:2,1:2) = K(1:2,1:2)+a;
K(2:3,2:3) = K(2:3,2:3)+b;

2 件のコメント

ajithAjith Reddy Moola
ajithAjith Reddy Moola 2020 年 4 月 3 日
That worked
Thanks!
Ameer Hamza
Ameer Hamza 2020 年 4 月 3 日
Glad to be of help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by