Block Diagonal
Versión 1.0.0 (1,68 KB) por
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)
Citar como
Lateef Adewale Kareem (2024). Block Diagonal (https://www.mathworks.com/matlabcentral/fileexchange/112325-block-diagonal), MATLAB Central File Exchange. Recuperado .
Compatibilidad con la versión de MATLAB
Se creó con
R2022a
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS LinuxEtiquetas
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Descubra Live Editor
Cree scripts con código, salida y texto formateado en un documento ejecutable.
Versión | Publicado | Notas de la versión | |
---|---|---|---|
1.0.0 |