diff src/ov-struct.cc @ 6946:10c7a803b409

[project @ 2007-10-03 14:38:48 by jwe]
author jwe
date Wed, 03 Oct 2007 14:38:48 +0000
parents e8a18d380097
children 9e32bb109980
line wrap: on
line diff
--- a/src/ov-struct.cc	Tue Oct 02 20:47:23 2007 +0000
+++ b/src/ov-struct.cc	Wed Oct 03 14:38:48 2007 +0000
@@ -560,7 +560,7 @@
 array with the specified field names.\n\
 @end deftypefn")
 {
-  octave_value_list retval;
+  octave_value retval;
 
   int nargin = args.length ();
 
@@ -572,8 +572,23 @@
   // Note that struct () creates a 1x1 struct with no fields for
   // compatibility with Matlab.
 
-  if (nargin == 1 && args(0).is_empty () && args(0).is_real_matrix ())
-    return octave_value (Octave_map (args(0).dims ()));
+  if ((nargin == 1 || nargin == 2)
+      && args(0).is_empty () && args(0).is_real_matrix ())
+    {
+      Cell fields;
+
+      if (nargin == 2)
+	{
+	  if (args(1).is_cellstr ())
+	    retval = Octave_map (args(0).dims (), args(1).cell_value ());
+	  else
+	    error ("struct: expecting cell array of field names as second argument");
+	}
+      else
+	retval = Octave_map (args(0).dims ());
+
+      return retval;
+    }
     
   // Check for "field", VALUE pairs.
 
@@ -658,7 +673,7 @@
       if (error_state)
 	return retval;
     }
-  
+
   return octave_value (map);
 }