changeset 12676:2783fa95cab7

Use common code idiom for creating cell array for indexing ND-arrays * int2str.m, interpft.m, num2str.m, postpad.m, prepad.m, shift.m, fftshift.m, ifftshift.m, unwrap.m
author Rik <octave@nomad.inbox5.com>
date Sun, 15 May 2011 10:50:30 -0700
parents 9493880928c8
children 69cd5ebe5fb5
files scripts/general/int2str.m scripts/general/interpft.m scripts/general/num2str.m scripts/general/postpad.m scripts/general/prepad.m scripts/general/shift.m scripts/signal/fftshift.m scripts/signal/ifftshift.m scripts/signal/unwrap.m
diffstat 9 files changed, 10 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/int2str.m	Sun May 15 08:58:49 2011 -0700
+++ b/scripts/general/int2str.m	Sun May 15 10:50:30 2011 -0700
@@ -55,10 +55,7 @@
     nd = ndims (n);
     nc = columns (n);
     if (nc > 1)
-      idx = cell ();
-      for i = 1:nd
-        idx{i} = 1:sz(i);
-      endfor
+      idx = repmat ({':'}, nd, 1);
       idx(2) = 1;
       ifmt = get_fmt (n(idx{:}), 0);
       idx(2) = 2:sz(2);
--- a/scripts/general/interpft.m	Sun May 15 08:58:49 2011 -0700
+++ b/scripts/general/interpft.m	Sun May 15 10:50:30 2011 -0700
@@ -76,10 +76,8 @@
   k = floor (m / 2);
   sz = size (x);
   sz(1) = n * inc - m;
-  idx = cell (nd, 1);
-  for i = 2:nd
-    idx{i} = 1:sz(i);
-  endfor
+
+  idx = repmat ({':'}, nd, 1);
   idx{1} = 1:k;
   z = cat (1, y(idx{:}), zeros (sz));
   idx{1} = k+1:m;
--- a/scripts/general/num2str.m	Sun May 15 08:58:49 2011 -0700
+++ b/scripts/general/num2str.m	Sun May 15 10:50:30 2011 -0700
@@ -111,10 +111,7 @@
     nd = ndims (x);
     perm = fix ([1:0.5:nc+0.5]);
     perm(2:2:2*nc) = perm(2:2:2*nc) + nc;
-    idx = cell ();
-    for i = 1:nd
-      idx{i} = 1:sz(i);
-    endfor
+    idx = repmat ({':'}, nd, 1);
     idx{2} = perm;
     x = horzcat (real (x), imag (x));
     x = x(idx{:});
--- a/scripts/general/postpad.m	Sun May 15 08:58:49 2011 -0700
+++ b/scripts/general/postpad.m	Sun May 15 10:50:30 2011 -0700
@@ -73,10 +73,7 @@
   d = sz (dim);
 
   if (d >= l)
-    idx = cell ();
-    for i = 1:nd
-      idx{i} = 1:sz(i);
-    endfor
+    idx = repmat ({':'}, nd, 1);
     idx{dim} = 1:l;
     y = x(idx{:});
   else
--- a/scripts/general/prepad.m	Sun May 15 08:58:49 2011 -0700
+++ b/scripts/general/prepad.m	Sun May 15 10:50:30 2011 -0700
@@ -73,10 +73,7 @@
   d = sz (dim);
 
   if (d >= l)
-    idx = cell ();
-    for i = 1:nd
-      idx{i} = 1:sz(i);
-    endfor
+    idx = repmat ({':'}, nd, 1);
     idx{dim} = d-l+1:d;
     y = x(idx{:});
   else
--- a/scripts/general/shift.m	Sun May 15 08:58:49 2011 -0700
+++ b/scripts/general/shift.m	Sun May 15 10:50:30 2011 -0700
@@ -60,10 +60,7 @@
 
   d = sz (dim);
 
-  idx = cell ();
-  for i = 1:nd
-    idx{i} = 1:sz(i);
-  endfor
+  idx = repmat ({':'}, nd, 1);
   if (b >= 0)
     b = rem (b, d);
     idx{dim} = [d-b+1:d, 1:d-b];
--- a/scripts/signal/fftshift.m	Sun May 15 08:58:49 2011 -0700
+++ b/scripts/signal/fftshift.m	Sun May 15 10:50:30 2011 -0700
@@ -58,9 +58,7 @@
     sz = size (x);
     sz2 = ceil (sz(dim) / 2);
     idx = cell ();
-    for i = 1:nd
-      idx{i} = 1:sz(i);
-    endfor
+    idx = repmat ({':'}, nd, 1);
     idx{dim} = [sz2+1:sz(dim), 1:sz2];
     retval = x(idx{:});
   else
--- a/scripts/signal/ifftshift.m	Sun May 15 08:58:49 2011 -0700
+++ b/scripts/signal/ifftshift.m	Sun May 15 10:50:30 2011 -0700
@@ -45,10 +45,7 @@
     nd = ndims (x);
     sz = size (x);
     sz2 = floor (sz(dim) / 2);
-    idx = cell ();
-    for i = 1:nd
-      idx{i} = 1:sz(i);
-    endfor
+    idx = repmat ({':'}, nd, 1);
     idx{dim} = [sz2+1:sz(dim), 1:sz2];
     retval = x(idx{:});
   else
--- a/scripts/signal/unwrap.m	Sun May 15 08:58:49 2011 -0700
+++ b/scripts/signal/unwrap.m	Sun May 15 10:50:30 2011 -0700
@@ -71,10 +71,7 @@
 
   ## Take first order difference to see so that wraps will show up
   ## as large values, and the sign will show direction.
-  idx = cell ();
-  for i = 1:nd
-    idx{i} = 1:sz(i);
-  endfor
+  idx = repmat ({':'}, nd, 1);
   idx{dim} = [1,1:m-1];
   d = x(idx{:}) - x;