Block Diagonal
Version 1.0.0 (1,68 KB) von
Lateef Adewale Kareem
This code allows you to process block diagonal elements. Its like the generalization of inbuilt diag.
% if size(v,2) == n
% D = diag(v) returns a square diagonal matrix with the block
% (m-by-n) elements of matrix v when on the main diagonal.
% D = diag(v, k) places the (m-by-n) elements of vector v on the kth
% block diagonal. k = 0 represents the main diagonal, k > 0 is above
% the main diagonal, and k<0 is below the main diagonal.
% end
% if size(v,2) > n
% D = diag(v) returns a matrix size(v, 1)-by-n made of block
% (m-by-n) main diagonal elements of matrix v.
% D = diag(v, k) extracts (m-by-n) block elements from matrix v on the
% kth block diagonal. k = 0 represents the main diagonal, k > 0 is above
% the main diagonal, and k<0 is below the main diagonal.
% end
% Note that if v has just 1 column, m = 1, and n = 1, then BlockDiag
% behaves exactly like the inbuilt function Diag.
A = rand(12);
v1 = BlockDiag(A, 2, 2)
v2 = BlockDiag(A, 2, 2, 1)
v3 = BlockDiag(A, 3, 2, -1)
v = rand(12,3);
D1 = BlockDiag(v, 3, 3)
D2 = BlockDiag(v, 3, 3, -1)
D3 = BlockDiag(v, 4, 3, 1)
Zitieren als
Lateef Adewale Kareem (2024). Block Diagonal (https://www.mathworks.com/matlabcentral/fileexchange/112325-block-diagonal), MATLAB Central File Exchange. Abgerufen.
Kompatibilität der MATLAB-Version
Erstellt mit
R2022a
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Live Editor erkunden
Erstellen Sie Skripte mit Code, Ausgabe und formatiertem Text in einem einzigen ausführbaren Dokument.
Version | Veröffentlicht | Versionshinweise | |
---|---|---|---|
1.0.0 |