如何在结构数组中添加新元素?我无法与空结构连接:
>> 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
令人难以置信的是,没有直接的方式!结构可能有一些冒号吗?