comparison scripts/general/cell2mat.m @ 10441:03d0dea2309d

support cells of cells in cell2mat
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 24 Mar 2010 07:13:44 +0100
parents c0d0b6e37a36
children 4975d63bb2df
comparison
equal deleted inserted replaced
10440:146e615b6674 10441:03d0dea2309d
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {@var{m} =} cell2mat (@var{c}) 20 ## @deftypefn {Function File} {@var{m} =} cell2mat (@var{c})
21 ## Convert the cell array @var{c} into a matrix by concatenating all 21 ## Convert the cell array @var{c} into a matrix by concatenating all
22 ## elements of @var{c} into a hyperrectangle. Elements of @var{c} must 22 ## elements of @var{c} into a hyperrectangle. Elements of @var{c} must
23 ## be numeric, logical or char, and @code{cat} must be able to 23 ## be numeric, logical or char matrices, or cell arrays, and @code{cat}
24 ## concatenate them together. 24 ## must be able to concatenate them together.
25 ## @seealso{mat2cell, num2cell} 25 ## @seealso{mat2cell, num2cell}
26 ## @end deftypefn 26 ## @end deftypefn
27 27
28 function m = cell2mat (c) 28 function m = cell2mat (c)
29 29
39 39
40 ## We only want numeric, logical, and char matrices. 40 ## We only want numeric, logical, and char matrices.
41 valid = cellfun (@isnumeric, c); 41 valid = cellfun (@isnumeric, c);
42 valid |= cellfun (@islogical, c); 42 valid |= cellfun (@islogical, c);
43 valid |= cellfun (@ischar, c); 43 valid |= cellfun (@ischar, c);
44 validc = cellfun (@iscell, c);
44 45
45 if (! all (valid)) 46 if (! all (valid(:)) && ! all (validc(:)))
46 error ("cell2mat: elements must be numeric, char or logical"); 47 error ("cell2mat: wrong type elements or mixed cells and matrices");
47 endif 48 endif
48 49
49 if (nb == 0) 50 if (nb == 0)
50 m = []; 51 m = [];
51 elseif (ndims (c) == 2) 52 elseif (ndims (c) == 2)