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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With