Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matrix direct sum

Is there a function in MATLAB that allows us to do matrix direct sum? For example,

A = [1 2 3
     3 4 5]
B = [5 6
     7 8
     9 8]

and we want the direct sum A ⊕ B that gives us:

directSum(A,B) = [1 2 3 0 0
                  3 4 5 0 0
                  0 0 0 5 6
                  0 0 0 7 8
                  0 0 0 9 8]

If there is not, what are some quick ways to implement this?

like image 364
IzzetTechPriest Avatar asked Dec 04 '25 14:12

IzzetTechPriest


1 Answers

Use blkdiag to compute the direct sum of matrices:

A = [1 2 3; 3 4 5];
B = [5 6; 7 8; 9 8];
blkdiag(A, B)

% ans = 5x5
%
%      1     2     3     0     0
%      3     4     5     0     0
%      0     0     0     5     6
%      0     0     0     7     8
%      0     0     0     9     8
like image 158
tdy Avatar answered Dec 07 '25 15:12

tdy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!