changeset 16077:39129305b914

provide some undocumented matlab behavior for linspace (bug #38151) * data.cc (Flinspace): Accept linspace (a, b, []).
author John W. Eaton <jwe@octave.org>
date Wed, 20 Feb 2013 19:29:41 -0500
parents c90c9623b20f
children 9439f3b5c5fa
files libinterp/interpfcn/data.cc
diffstat 1 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/interpfcn/data.cc	Wed Feb 20 16:11:47 2013 -0800
+++ b/libinterp/interpfcn/data.cc	Wed Feb 20 19:29:41 2013 -0500
@@ -4729,7 +4729,17 @@
     }
 
   if (nargin == 3)
-    npoints = args(2).idx_type_value ();
+    {
+      // Apparently undocumented Matlab.  If the third arg is an empty
+      // numeric value, the number of points defaults to 1.
+
+      octave_value arg_3 = args(2);
+
+      if (arg_3.is_numeric_type () && arg_3.is_empty ())
+        npoints = 1;
+      else
+        npoints = arg_3.idx_type_value ();
+    }
 
   if (! error_state)
     {
@@ -4770,6 +4780,8 @@
 
 %assert (linspace ([1, 2; 3, 4], 5, 6), linspace (1, 5, 6))
 
+%assert (linspace (0, 1, []), 1)
+
 %!error linspace ()
 %!error linspace (1, 2, 3, 4)
 */