Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 包含字符串和单元格的结构的MATLAB行为_String_Matlab_Struct_Cell - Fatal编程技术网

String 包含字符串和单元格的结构的MATLAB行为

String 包含字符串和单元格的结构的MATLAB行为,string,matlab,struct,cell,String,Matlab,Struct,Cell,我想要一个包含字符串的结构和字符串的单元格数组 这与预期的效果一样: x = struct('field1','one','field2','two'); >> x.field1 ans = one 但只要我有一个字符串单元格数组,这就是x.field1的输出: x = struct('field1','one','field2',{'two','three'}); >> x.field1 ans = one ans = one 您能告

我想要一个包含字符串的结构和字符串的单元格数组

这与预期的效果一样:

x = struct('field1','one','field2','two');
>> x.field1
ans =    
one
但只要我有一个字符串单元格数组,这就是
x.field1
的输出:

x = struct('field1','one','field2',{'two','three'});
>> x.field1    
ans =    
one
ans =    
one

您能告诉我如何将字符串和单元格数组正确地组合到一个结构中吗?谢谢

在单元格数组周围添加两个大括号,以防止Matlab将其内容分发到结构数组中:

>>x = struct('field1','one','field2',{{'two','three'}})
x = 
    field1: 'one'
    field2: {'two'  'three'}

我试过使用八度音阶,这样的定义似乎会导致1x2结构数组,与field1相关的两个条目的值都是“一”。如果您将x定义为以下内容,则情况有所不同:
x=struct('field1','one','field2',struct('subfield1','two','subfield2','three')