Create a block diagonal matrix - MATLAB Cody - MATLAB Central

Problem 2813. Create a block diagonal matrix

Difficulty:Rate

A block diagonal matrix is a square matrix that can be written as

   A = [a  0  0  0
        0  b  0  0
        0  0  c  0
        0  0  0 ...]

where a, b, c etc. are all square matrices.

Construct A such that

   A = [a  0  0  0
        0  a  0  0
        0  0  a  0
        0  0  0 ...]

where a is allowed to be non-square or empty and occurs n times. n is always an integer greater than or equal to 0.

Examples:

   a = [1 2 3], n = 3

gives

   A = [1 2 3 0 0 0 0 0 0
        0 0 0 1 2 3 0 0 0
        0 0 0 0 0 0 1 2 3]

Solution Stats

42.54% Correct | 57.46% Incorrect
Last Solution submitted on Jan 06, 2025

Problem Comments

Solution Comments

Show comments
R2025a Pre-release highlights
This topic is for discussing highlights to the current R2025a Pre-release.
13
5

Problem Recent Solvers142

Suggested Problems

More from this Author1

Problem Tags

Community Treasure Hunt

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

Start Hunting!
Go to top of page