Reputation: 34601
blkdiag
uses varargin
to construct a block diagonal matrix from the input arguments (each matrix which needs to be inserted into the diagonal).
out = blkdiag(a,b,c,d,...)
, wherea, b, c, d, ...
are matrices, outputs a block diagonal matrix of the form
Suppose I had a cell array of matrices (or some other data structure) ; how would I feed this to a function like blkdiag
?
Upvotes: 1
Views: 728
Reputation: 2502
Use {:} to expand it for the function:
blocks = cell(2);
blocks{1} = rand(2);
blocks{2} = rand(2);
out = blkdiag(blocks{:})
Answer:
out =
0.6787 0.7431 0 0
0.7577 0.3922 0 0
0 0 0.6555 0.7060
0 0 0.1712 0.0318
Upvotes: 3