changeset 12674:9493880928c8

Use common idiom in m-files for finding first non-singleton dimension. * flipdim.m, postpad.m, prepad.m, shift.m, unwrap.m: Use common idiom in m-files for finding first non-singleton dimension.
author Rik <octave@nomad.inbox5.com>
date Sun, 15 May 2011 08:58:49 -0700
parents 64193afe93d8
children 2783fa95cab7
files scripts/general/flipdim.m scripts/general/postpad.m scripts/general/prepad.m scripts/general/shift.m scripts/signal/unwrap.m
diffstat 5 files changed, 8 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/flipdim.m
+++ b/scripts/general/flipdim.m
@@ -45,7 +45,7 @@
   nd = ndims (x);
   if (nargin == 1)
     ## Find the first non-singleton dimension.
-    [~, dim] = min (size (x) != 1);
+    (dim = find (sz > 1, 1)) || (dim = 1);
   elseif (! (isscalar (dim) && isindex (dim)))
     error ("flipdim: DIM must be a positive integer");
   endif
--- a/scripts/general/postpad.m
+++ b/scripts/general/postpad.m
@@ -53,11 +53,8 @@
   nd = ndims (x);
   sz = size (x);
   if (nargin < 4)
-    ## Find the first non-singleton dimension
-    dim = find (sz > 1, 1);
-    if (isempty (dim))
-      dim = 1;
-    endif
+    ## Find the first non-singleton dimension.
+    (dim = find (sz > 1, 1)) || (dim = 1);
   else
     if (!(isscalar (dim) && dim == fix (dim))
         || !(1 <= dim && dim <= nd))
--- a/scripts/general/prepad.m
+++ b/scripts/general/prepad.m
@@ -53,11 +53,8 @@
   nd = ndims (x);
   sz = size (x);
   if (nargin < 4)
-    ## Find the first non-singleton dimension
-    dim = find (sz > 1, 1);
-    if (isempty (dim))
-      dim = 1;
-    endif
+    ## Find the first non-singleton dimension.
+    (dim = find (sz > 1, 1)) || (dim = 1);
   else
     if (!(isscalar (dim) && dim == fix (dim))
         || !(1 <= dim && dim <= nd))
--- a/scripts/general/shift.m
+++ b/scripts/general/shift.m
@@ -51,10 +51,7 @@
     endif
   else
     ## Find the first non-singleton dimension.
-    dim = find (sz > 1, 1);
-    if (isempty (dim))
-      dim = 1;
-    endif
+    (dim = find (sz > 1, 1)) || (dim = 1);
   endif
 
   if (numel (x) < 1)
--- a/scripts/signal/unwrap.m
+++ b/scripts/signal/unwrap.m
@@ -55,11 +55,8 @@
       error ("unwrap: DIM must be an integer and a valid dimension");
     endif
   else
-    ## Find the first non-singleton dimension
-    dim = find (sz > 1, 1);
-    if (isempty (dim))
-      dim = 1;
-    endif
+    ## Find the first non-singleton dimension.
+    (dim = find (sz > 1, 1)) || (dim = 1);
   endif
 
   rng = 2*pi;