如何将新元素添加到结构数组中?我无法与空结构连接:如何在Matlab中将新元素添加到结构数组中?
>> a=struct;
>> a.f1='hi'
a =
f1: 'hi'
>> a.f2='bye'
a =
f1: 'hi'
f2: 'bye'
>> a=cat(1,a,struct)
Error using cat
Number of fields in structure arrays being concatenated do not match. Concatenation of structure arrays requires that these arrays have the same set of
fields.
那么是否有可能添加空字段的新元素?
UPDATE
我发现我可以添加新的元素,如果我同时添加新的领域:
>> a=struct()
a =
struct with no fields.
>> a.f1='hi';
>> a.f2='bye';
>> a(end+1).iamexist=true
a =
1x2 struct array with fields:
f1
f2
iamexist
令人难以置信的是,没有直通!可能有一些冒号相当于结构?
你可以这样做:'a(n)= a(1)' – Dan