# HG changeset patch # User Jaroslav Hajek # Date 1261991004 -3600 # Node ID e60f038146e17fd505ddb52d2c1f3380b2becaa4 # Parent 0cabc95f08335592a467a293ec45e63515193ec3 further simplify strcat diff -r 0cabc95f0833 -r e60f038146e1 scripts/ChangeLog --- a/scripts/ChangeLog Sun Dec 27 22:19:07 2009 -0500 +++ b/scripts/ChangeLog Mon Dec 28 10:03:24 2009 +0100 @@ -1,3 +1,7 @@ +2009-12-28 Jaroslav Hajek + + * strings/strcat.m: Further simplify. + 2009-12-27 Jaroslav Hajek * general/common_size.m: Optimize. diff -r 0cabc95f0833 -r e60f038146e1 scripts/strings/strcat.m --- a/scripts/strings/strcat.m Sun Dec 27 22:19:07 2009 -0500 +++ b/scripts/strings/strcat.m Mon Dec 28 10:03:24 2009 +0100 @@ -73,29 +73,20 @@ error ("strcat: inputs must be strings or cells of strings"); endif - ## Set all cells to a common size - [err, varargin{:}] = common_size (varargin{:}); + ## We don't actually need to bring all cells to common size, because + ## cellfun can now expand scalar cells. + err = common_size (varargin{:}); if (err) error ("strcat: arguments must be the same size, or be scalars"); endif - ## Total number of resulting strings. - dims = size (varargin{1}); - nstr = prod (dims); - ## Reshape args to column vectors. - varargin = cellfun (@reshape, varargin, {[nstr, 1]}, uo, false); - ## Concatenate the columns to a cell matrix, and extract rows. - strows = num2cell ([varargin{:}], 2); - ## Concatenate all the rows. - st = cellfun (@cell2mat, strows, uo, false); + ## Cellfun handles everything for us. + st = cellfun (@horzcat, varargin{:}, uo, false); if (allchar) ## If all inputs were strings, return strings. st = char (st); - else - ## Reshape to original dims - st = reshape (st, dims); endif endif else