blkdiag
Block diagonal matrix
Syntax
Description
B = blkdiag(
returns the block diagonal
matrix created by aligning the input matrices A1,...,AN
)A1,...,AN
along
the diagonal of B
.
Examples
Create a block diagonal matrix from three matrices of different sizes.
A1 = ones(2,2); A2 = 2*ones(3,2); A3 = 3*ones(2,3); B = blkdiag(A1,A2,A3)
B = 7×7
1 1 0 0 0 0 0
1 1 0 0 0 0 0
0 0 2 2 0 0 0
0 0 2 2 0 0 0
0 0 2 2 0 0 0
0 0 0 0 3 3 3
0 0 0 0 3 3 3
Input Arguments
Input matrices, specified as a comma-separated list of matrices. The matrices can be either square or rectangular and can differ in size.
If any of the input matrices are sparse, then the output block diagonal matrix is also sparse.
More About
A block diagonal matrix is a matrix whose diagonal contains blocks of smaller matrices, in contrast to a regular diagonal matrix with single elements along the diagonal. A block diagonal matrix takes on the following form, where A1, A2,…, AN are each matrices that can differ in size:
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
The blkdiag
function
fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray
(Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced before R2006a
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)