diff liboctave/Array-util.cc @ 9666:a531dec450c4

allow 1D case for sub2ind and ind2sub
author Jaroslav Hajek <highegg@gmail.com>
date Sun, 27 Sep 2009 11:26:41 +0200
parents a9b37bae1802
children 4c0cdbe0acca
line wrap: on
line diff
--- a/liboctave/Array-util.cc
+++ b/liboctave/Array-util.cc
@@ -496,7 +496,7 @@
   idx_vector retval;
   octave_idx_type len = idxa.length ();
 
-  if (len >= 2)
+  if (len >= 1)
     {
       const dim_vector dvx = dv.redim (len);
       bool all_ranges = true;
@@ -517,7 +517,9 @@
             current_liboctave_error_handler ("sub2ind: index out of range");
         }
 
-      if (clen == 1)
+      if (len == 1)
+        retval = idxa(0);
+      else if (clen == 1)
         {
           // All scalars case - the result is a scalar.
           octave_idx_type idx = idxa(len-1)(0);