# HG changeset patch # User Ben Abbott # Date 1290363265 18000 # Node ID 107e7476a5da4955e944145c0b72111cda9dfa90 # Parent b9bc32327c4dd72da11bbe8706af5ba56b2a5851 cell2mat.m: Return empty matrix for empty cell. diff -r b9bc32327c4d -r 107e7476a5da scripts/ChangeLog --- a/scripts/ChangeLog Sun Nov 21 18:36:27 2010 +0100 +++ b/scripts/ChangeLog Sun Nov 21 13:14:25 2010 -0500 @@ -1,3 +1,7 @@ +2010-11-21 Ben Abbott + + * general/cell2mat.m: Return empty matrix for empty cell. + 2010-11-21 Kai Habel * (plot/uigetfile.m, plot/uiputfile.m): Set default directory to pwd diff -r b9bc32327c4d -r 107e7476a5da scripts/general/cell2mat.m --- a/scripts/general/cell2mat.m Sun Nov 21 18:36:27 2010 +0100 +++ b/scripts/general/cell2mat.m Sun Nov 21 13:14:25 2010 -0500 @@ -38,20 +38,21 @@ nb = numel (c); - ## We only want numeric, logical, and char matrices. - valid = cellfun (@isnumeric, c); - valid |= cellfun (@islogical, c); - valid |= cellfun (@ischar, c); - validc = cellfun (@iscell, c); - valids = cellfun (@isstruct, c); - - if (! all (valid(:)) && ! all (validc(:)) && ! all (valids(:))) - error ("cell2mat: wrong type elements or mixed cells, structs and matrices"); - endif - if (nb == 0) m = []; else + + ## We only want numeric, logical, and char matrices. + valid = cellfun (@isnumeric, c); + valid |= cellfun (@islogical, c); + valid |= cellfun (@ischar, c); + validc = cellfun (@iscell, c); + valids = cellfun (@isstruct, c); + + if (! all (valid(:)) && ! all (validc(:)) && ! all (valids(:))) + error ("cell2mat: wrong type elements or mixed cells, structs and matrices"); + endif + ## The goal is to minimize the total number of cat() calls. ## The dimensions can be concatenated along in arbitrary order. ## The numbers of concatenations are: @@ -96,6 +97,7 @@ %!test %! m = {1, 2, 3}; %! assert (cell2mat (mat2cell (m, 1, [1 1 1])), m); +%!assert (cell2mat ({}), []); ## Demos %!demo %! C = {[1], [2 3 4]; [5; 9], [6 7 8; 10 11 12]};