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
If you know a function which is used to create a matrix, you can solve this problem easily !
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 commentsProblem Recent Solvers160
Suggested Problems
-
What is the distance from point P(x,y) to the line Ax + By + C = 0?
547 Solvers
-
Given a matrix, swap the 2nd & 3rd columns
1216 Solvers
-
637 Solvers
-
Convert a Cell Array into an Array
2081 Solvers
-
Let's get back to school, and create multiplication tables
229 Solvers
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!