Creation of a block-diagonal sparse matrix
Show older comments
I would like to create a block-diagonal matrix with the following properties:
- The matrix must consist of submatrices A1, A2, ... on the diagonal and zeroes elsewhere.
- Each submatrix will be square, but dimensions vary.
- Each n-by-n submatrix takes the following shape:
eye(n) - ones(1/n)
- Since there are many such submatrices, the overall matrix must be sparse.
What I have is a vector which holds the dimensions of each submatrix. So, if the vector is, say, b=[1,5,3,...], then the first submatrix A1 would have to be 1-by-1, A2 is 5-by-5, A3 is 3-by-3, and so on. How do I go from there to the creation of my matrix?
Two answers were given on a related quation. The first, based upon blkdiag, won't work, because it would involve temporarily creating the full matrix, and I run out of memory. The second seems preferable, but I can't wrap my head around how to adopt it to my setting.
2 Comments
Matt J
on 7 Dec 2014
What is ones(1/n)? Taken literally, it should give an error for any integer n>1,
>> ones(1/2)
Error using ones
Size inputs must be integers.
Accepted Answer
More Answers (0)
Categories
Find more on Sparse Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!