time | Calls | line |
---|
| | 1 | function y = blkdiag(varargin)
|
| | 2 | %BLKDIAG Block diagonal concatenation of matrix input arguments.
|
| | 3 | %
|
| | 4 | % |A 0 .. 0|
|
| | 5 | % Y = BLKDIAG(A,B,...) produces |0 B .. 0|
|
| | 6 | % |0 0 .. |
|
| | 7 | %
|
| | 8 | % Class support for inputs:
|
| | 9 | % float: double, single
|
| | 10 | % integer: uint8, int8, uint16, int16, uint32, int32, uint64, int64
|
| | 11 | % char, logical
|
| | 12 | %
|
| | 13 | % See also DIAG, HORZCAT, VERTCAT
|
| | 14 |
|
| | 15 | % Copyright 1984-2013 The MathWorks, Inc.
|
| | 16 |
|
0.005 | 18254 | 17 | if nargin > 0
|
0.362 | 18254 | 18 | outclass = class(varargin{1});
|
0.390 | 18254 | 19 | if isobject(varargin{1}) || ~isnumeric(varargin{1}) || ...
|
| 18254 | 20 | any(~cellfun('isclass',varargin,outclass))
|
| | 21 | y = [];
|
| | 22 | for k=1:nargin
|
| | 23 | x = varargin{k};
|
| | 24 | [p1,m1] = size(y);
|
| | 25 | [p2,m2] = size(x);
|
| | 26 | y = [y zeros(p1,m2); zeros(p2,m1) x]; %#ok
|
| | 27 | end
|
| | 28 | return
|
| | 29 | end
|
| | 30 | else
|
| | 31 | outclass = 'double';
|
0.001 | 18254 | 32 | end
|
| | 33 |
|
5.275 | 18254 | 34 | if any(cellfun(@issparse,varargin));
|
| | 35 | % optimized MEX implementation for sparse double
|
0.214 | 4062 | 36 | y = blkdiagmex(varargin{:});
|
0.001 | 14192 | 37 | else
|
4.614 | 14192 | 38 | [p2,m2] = cellfun(@size,varargin);
|
| | 39 | %Precompute cumulative matrix sizes
|
0.192 | 14192 | 40 | p1 = [0, cumsum(p2)];
|
0.049 | 14192 | 41 | m1 = [0, cumsum(m2)];
|
| | 42 |
|
0.604 | 14192 | 43 | y = zeros(p1(end),m1(end),outclass); %Preallocate
|
0.005 | 14192 | 44 | for k=1:nargin
|
25.650 | 2809428 | 45 | y(p1(k)+1:p1(k+1),m1(k)+1:m1(k+1)) = varargin{k};
|
0.132 | 2809428 | 46 | end
|
0.181 | 18254 | 47 | end
|
Other subfunctions in this file are not included in this listing.