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
Diagonal of Three Matrices
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
A1,...,AN
— Input matrices
matrices
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
Block Diagonal Matrix
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™.
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced before R2006a
See Also
Beispiel öffnen
Sie haben eine geänderte Version dieses Beispiels. Möchten Sie dieses Beispiel mit Ihren Änderungen öffnen?
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)