Block Diagonal

This code allows you to process block diagonal elements. Its like the generalization of inbuilt diag.
7.0 次下载
更新时间 2022/5/27

查看许可证

% 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)

引用格式

Lateef Adewale Kareem (2024). Block Diagonal (https://www.mathworks.com/matlabcentral/fileexchange/112325-block-diagonal), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2022a
兼容任何版本
平台兼容性
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0