SPBLKDIAG Block diagonal concatenation of matrix input arguments, with sparse output.
Y = SPBLKDIAG(A,B,...) produces SPARSE(BLKDIAG(A, B, ..)) efficiently, where A, B, ... are matrices of class double (real or complex).
Basically, this is a thin wrapper around MATLAB's own BLKDIAG, since it already supports sparse output. However:
- BLKDIAG does not mention sparse support in its documentation; nor the fact that it is supported, nor how to access the functionality.
- BLKDIAG's name is inconsistent with the function names for any of MATLAB's other sparse functions (SPEYE, SPDIAGS, etc.)
Therefore, until The MathWorks fixes this, this function provides a better documented and more intuitively named alternative to BLKDIAG.
@Yutao Chen I'm sorry you feel this way. What blkdiag() does is call blkdiagmex() whenever it receives sparse input. This is (presumably) a C-MEX function that is as fast as it will get without sacrificing generality. What my function does is cast only the smallest matrix to sparse(), and then call blkdiag() which immediately calls blkdiagmex() because it sees a sparse matrix...I don't see how that can be done any faster. If you can give an example of inputs that make this function slow, I can perhaps analyze the problem and improve things a bit.
I'd like to see a function that can concatnate sparse matrix into a block diagonal matrix EFFICIENTLY!
A Simply wrapper of the sparse and blkdiag functions is not efficient.
I think a good implementation requires spdiag, with some careful coding.
Please, people, 1 or 2 star ratings tell me nothing. Please leave a message, however brief, so that I can improve/update/remove my code.
fixed typos in the description.