Mercurial > hg > octave-lyh
changeset 6023:75a828280d68
[project @ 2006-10-03 02:14:21 by jwe]
author | jwe |
---|---|
date | Tue, 03 Oct 2006 02:14:21 +0000 |
parents | abd750456740 |
children | 500d884ae373 |
files | scripts/ChangeLog scripts/general/__isequal__.m scripts/strings/deblank.m scripts/strings/lower.m scripts/strings/upper.m |
diffstat | 5 files changed, 15 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2006-10-02 Bill Denney <denney@seas.upenn.edu> + + * strings/deblank.m, strings/upper.m, strings/lower.m, + general/__isequal__.m: Minimize looping using cellfun. + 2006-10-02 David Bateman <dbateman@free.fr> * pkg/pkg.m (copy_files): always create installation directory.
--- a/scripts/general/__isequal__.m +++ b/scripts/general/__isequal__.m @@ -54,11 +54,10 @@ n_x = length (fieldnames (x)); - t = true; - for argn = 1:l_v - y = varargin{argn}; - t = t && isstruct (y) && (n_x == length (fieldnames (y))); - endfor + t = all (cellfun (@isstruct, varargin)) && ... + all (n_x == cellfun (@length, + cellfun (@fieldnames, varargin, + "UniformOutput", false))); if (!t) return; endif @@ -79,16 +78,13 @@ endif endfor - elseif ((iscell (x)) || (islist (x))) + elseif (iscell (x) || islist (x)) x = x(:); l_x = length (x); - t = true; - for argn = 1:l_v - y = varargin{argn}(:); - t = t && (iscell (y) || islist (y)) && (l_x == length (y)); - endfor + t = all ((cellfun (@iscell, varargin) | cellfun (@islist, varargin)) && ... + all (l_x == cellfun (@length, varargin))); if (!t) return; endif
--- a/scripts/strings/deblank.m +++ b/scripts/strings/deblank.m @@ -45,9 +45,7 @@ elseif (iscell(s)) - for i = 1:numel (s) - s{i} = deblank (s{i}); - endfor + s = cellfun (@deblank, s, "UniformOutput", false); else error ("deblank: expecting string argument");
--- a/scripts/strings/lower.m +++ b/scripts/strings/lower.m @@ -35,10 +35,7 @@ if (ischar (s)) retval = tolower (s); elseif (iscellstr (s)) - retval = cell (size (s)); - for i = 1:(numel (s)) - retval{i} = tolower(s{i}); - endfor + retval = cellfun (@tolower, s, "UniformOutput", false); else error ("lower: `s' must be a string or cell array of strings"); endif
--- a/scripts/strings/upper.m +++ b/scripts/strings/upper.m @@ -35,10 +35,7 @@ if (ischar (s)) retval = toupper (s); elseif (iscellstr (s)) - retval = cell (size (s)); - for i = 1:(numel (s)) - retval{i} = toupper(s{i}); - endfor + retval = cellfun (@toupper, s, "UniformOutput", false); else error ("upper: `s' must be a string or cell array of strings"); endif