changeset 8612:20d23d65cc84

fix & optimize orderfields
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 28 Jan 2009 07:23:35 +0100
parents 1e47b5f04b4c
children 38482007c834
files scripts/ChangeLog scripts/miscellaneous/orderfields.m
diffstat 2 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Tue Jan 27 23:48:57 2009 -0500
+++ b/scripts/ChangeLog	Wed Jan 28 07:23:35 2009 +0100
@@ -1,3 +1,8 @@
+2009-01-28  Jaroslav Hajek  <highegg@gmail.com>
+
+	* miscellaneous/ordefields.m: Use indexed assignment instead of a
+	loop. Fix for multidimensional cases.
+
 2009-01-27  John W. Eaton  <jwe@octave.org>
 
 	* general/arrayfun.m, image/imwrite.m, plot/axis.m, plot/clf.m,
--- a/scripts/miscellaneous/orderfields.m	Tue Jan 27 23:48:57 2009 -0500
+++ b/scripts/miscellaneous/orderfields.m	Wed Jan 28 07:23:35 2009 +0100
@@ -93,12 +93,13 @@
     args(2:2:end) = {[]};
     t = struct (args{:});
   else
+    n = numel (s1);
     for i = 1:numel (names)
       el = names(i);
-      for k = 1:length (s1)
-	t(k).(el) = s1(k).(el);
-      endfor
+      [t(1:n).(el)] = s1(:).(el);
     endfor
+    ## inherit dimensions
+    t = reshape (t, size (s1));
   endif
 
 endfunction