# HG changeset patch # User jwe # Date 1188974969 0 # Node ID d63339cbb2050b9ccd841442b7d721df0b5101dd # Parent 32558239ed9eac3b13dcc5c307719f075e0c6c13 [project @ 2007-09-05 06:49:29 by jwe] diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,11 @@ +2007-09-05 John W. Eaton + + * miscellaneous/orderfields.m: Use numel instead of length. + +2007-09-05 Michael goffioul + + * miscellaneous/orderfields.m: Handle empty structs. + 2007-09-05 John W. Eaton * plot/__go_draw_axes__.m: Consistently index PARAMETRIC with diff --git a/scripts/miscellaneous/orderfields.m b/scripts/miscellaneous/orderfields.m --- a/scripts/miscellaneous/orderfields.m +++ b/scripts/miscellaneous/orderfields.m @@ -46,11 +46,11 @@ if (nargin == 1) ## One structure: return the fields in alphabetical order. - if (isstruct(s1)) + if (isstruct (s1)) names = sort (fieldnames (s1)); endif elseif (nargin == 2) - if (isstruct(s2)) + if (isstruct (s2)) ## Two structures: return the fields in the order of s2. names = fieldnames (s2); if (! isequal (sort (fieldnames (s1)), sort (names))) @@ -69,11 +69,11 @@ names = fieldnames (s1); t1 = sort (s2); t1 = t1(:)'; - t2 = 1:length (names); + t2 = 1:numel (names); if (! isequal (t1, t2)) error ("orderfields: invalid permutation vector"); endif - names = names(s2); + names = names (s2); endif endif @@ -88,9 +88,16 @@ endif ## Permute the names in the structure. - for i = 1:length (names) - el = names(i); - t(:).(el) = s1(:).(el); - endfor + if (numel (s1) == 0) + args = cell (1, 2 * numel (names)); + args(1:2:end) = names; + args{2:2:end} = {}; + t = struct (args{:}); + else + for i = 1:numel (names) + el = names(i); + t(:).(el) = s1(:).(el); + endfor + endif endfunction