diff 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
line wrap: on
line diff
--- a/scripts/general/cell2mat.m
+++ b/scripts/general/cell2mat.m
@@ -20,8 +20,8 @@
 ## @deftypefn {Function File} {@var{m} =} cell2mat (@var{c})
 ## Convert the cell array @var{c} into a matrix by concatenating all
 ## elements of @var{c} into a hyperrectangle.  Elements of @var{c} must
-## be numeric, logical or char, and @code{cat} must be able to
-## concatenate them together.
+## be numeric, logical or char matrices, or cell arrays, and @code{cat} 
+## must be able to concatenate them together.
 ## @seealso{mat2cell, num2cell}
 ## @end deftypefn
 
@@ -41,9 +41,10 @@
   valid = cellfun (@isnumeric, c);
   valid |= cellfun (@islogical, c);
   valid |= cellfun (@ischar, c);
+  validc = cellfun (@iscell, c);
 
-  if (! all (valid))
-    error ("cell2mat: elements must be numeric, char or logical");
+  if (! all (valid(:)) && ! all (validc(:)))
+    error ("cell2mat: wrong type elements or mixed cells and matrices");
   endif
 
   if (nb == 0)