Mercurial > hg > octave-max
changeset 10037:e60f038146e1
further simplify strcat
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 28 Dec 2009 10:03:24 +0100 |
parents | 0cabc95f0833 |
children | 62eb444704ba |
files | scripts/ChangeLog scripts/strings/strcat.m |
diffstat | 2 files changed, 9 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2009-12-28 Jaroslav Hajek <highegg@gmail.com> + + * strings/strcat.m: Further simplify. + 2009-12-27 Jaroslav Hajek <highegg@gmail.com> * general/common_size.m: Optimize.
--- a/scripts/strings/strcat.m +++ b/scripts/strings/strcat.m @@ -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