comparison scripts/general/blkdiag.m @ 5989:e049385342f6

[project @ 2006-09-14 02:10:46 by jwe]
author jwe
date Thu, 14 Sep 2006 02:10:46 +0000
parents 067948dc39bf
children 34f96dd5441b
comparison
equal deleted inserted replaced
5988:d9ce802628e6 5989:e049385342f6
30 30
31 if (nargin < 1) 31 if (nargin < 1)
32 usage ("blkdiag (a, b, c, ...)"); 32 usage ("blkdiag (a, b, c, ...)");
33 endif 33 endif
34 34
35 if (! all (cell2mat (cellfun (@isnumeric, varargin)))) 35 if (! all (cellfun (@isnumeric, varargin)))
36 error ("blkdiag: all arguments must be numeric"); 36 error ("blkdiag: all arguments must be numeric");
37 endif 37 endif
38 38
39 ## Note: trailing singletons are automatically (correctly) ignored. 39 ## Note: trailing singletons are automatically (correctly) ignored.
40 if (! all (cellfun ("ndims", varargin) == 2)) 40 if (! all (cellfun ("ndims", varargin) == 2))
41 error ("blkdiag: all arguments must be two-dimensional matrices"); 41 error ("blkdiag: all arguments must be two-dimensional matrices");
42 endif 42 endif
43 43
44 ## size is an option for cellfun, but it's a bit different from 44 ## size is an option for cellfun, but it's a bit different from
45 ## calling size directly. 45 ## calling size directly.
46 csz = cumsum ([0 0; (cell2mat (cellfun (@size, varargin')))], 1); 46 tmp = cell2mat (cellfun (@size, varargin', "UniformOutput", false));
47 csz = cumsum ([0 0; tmp], 1);
47 retval = zeros (csz(end,:)); 48 retval = zeros (csz(end,:));
48 49
49 for p = 1:nargin 50 for p = 1:nargin
50 retval((csz(p,1)+1):csz(p+1,1),(csz(p,2)+1):csz(p+1,2)) = varargin{p}; 51 retval((csz(p,1)+1):csz(p+1,1),(csz(p,2)+1):csz(p+1,2)) = varargin{p};
51 endfor 52 endfor