Problem 2813. Create a block diagonal matrix
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
Problem Comments
-
2 Comments
Masato Kanematsu
on 1 Oct 2020
If you know a function which is used to create a matrix, you can solve this problem easily !
Dyuman Joshi
on 27 Dec 2020
I thought you referred to the function blkdiag(), but I am surprised to know that it is not the case (for a one-liner)!
Solution Comments
Show commentsGroup

Project Euler II
- 12 Problems
- 51 Finishers
- Find the longest sequence of 1's in a binary sequence.
- Convert given decimal number to binary number.
- Find out sum and carry of Binary adder
- Binary numbers
- Given an unsigned integer x, find the largest y by rearranging the bits in x
- Bit Reversal
- Relative ratio of "1" in binary number
- Binary code (array)
- Converting binary to decimals
- There are 10 types of people in the world
Problem Recent Solvers143
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!