Block Diagonal
Versione 1.0.0 (1,68 KB) da
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)
Cita come
Lateef Adewale Kareem (2025). Block Diagonal (https://www.mathworks.com/matlabcentral/fileexchange/112325-block-diagonal), MATLAB Central File Exchange. Recuperato .
Compatibilità della release di MATLAB
Creato con
R2022a
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS LinuxTag
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Scopri Live Editor
Crea script con codice, output e testo formattato in un unico documento eseguibile.
Versione | Pubblicato | Note della release | |
---|---|---|---|
1.0.0 |