@@ -1817,8 +1817,8 @@ orderfields, isstruct, structfun}
1817
1817
1818
1818
// struct ([]) returns an empty struct.
1819
1819
1820
- // struct (empty_matrix) returns an empty struct with the same
1821
- // dimensions as the empty matrix.
1820
+ // struct (empty_matrix) or struct (empty_matrix, cell_array_of field_names)
1821
+ // return an empty struct with the same dimensions as the empty matrix.
1822
1822
1823
1823
// Note that struct () creates a 1x1 struct with no fields for
1824
1824
// compatibility with Matlab.
@@ -1830,7 +1830,8 @@ orderfields, isstruct, structfun}
1830
1830
return ovl (args (0 ).map_value ());
1831
1831
1832
1832
if ((nargin == 1 || nargin == 2 )
1833
- && args (0 ).isempty () && args (0 ).is_real_matrix ())
1833
+ && args (0 ).isempty () && args (0 ).is_real_matrix ()
1834
+ && ! args (0 ).is_char_matrix ())
1834
1835
{
1835
1836
if (nargin == 2 )
1836
1837
{
@@ -1933,6 +1934,10 @@ orderfields, isstruct, structfun}
1933
1934
%!error <arguments must occur as "field", VALUE pairs> struct (1,2,3,4)
1934
1935
%!fail ('struct ("1",2,"3")',
1935
1936
%! 'struct: additional arguments must occur as "field", VALUE pairs')
1937
+
1938
+ %!test <*67255> # Test empty string as field name
1939
+ % s.('') = 3;
1940
+ % assert (struct ('', 3), s)
1936
1941
*/
1937
1942
1938
1943
DEFUN (isstruct, args, ,
@@ -2069,7 +2074,7 @@ get_cell2struct_fields (const octave_value& arg)
2069
2074
{
2070
2075
if (arg.is_string ())
2071
2076
{
2072
- if (arg.rows () != 1 )
2077
+ if (arg.rows () > 1 )
2073
2078
invalid_cell2struct_fields_error ();
2074
2079
2075
2080
return Array<std::string> (dim_vector (1 , 1 ), arg.string_value ());
@@ -2085,7 +2090,7 @@ get_cell2struct_fields (const octave_value& arg)
2085
2090
{
2086
2091
const octave_value val = c (i);
2087
2092
2088
- if (! val.is_string () || val.rows () != 1 )
2093
+ if (! val.is_string () || val.rows () > 1 )
2089
2094
invalid_cell2struct_fields_error ();
2090
2095
2091
2096
retval (i) = c (i).string_value ();
@@ -2202,6 +2207,9 @@ S(1)
2202
2207
%!assert (cell2struct ({1, 2, 3, 4}, {'a', 'b'; 'c', 'd'}, 2),
2203
2208
%! struct ('a', 1, 'c', 2, 'b', 3, 'd', 4));
2204
2209
%!error cell2struct ({1, 2, 3, 4}, {'a', 'b'; 'c', 'd'})
2210
+
2211
+ %!test <*67255> # Test empty string as field name
2212
+ % assert (cell2struct ({3}, {''}), struct ('', {3}))
2205
2213
*/
2206
2214
2207
2215
DEFUN (rmfield, args, ,
0 commit comments