如何向结构数组中添加新元素?我无法与空结构连接起来:
>> 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.
能否添加新的空字段元素?
更新
我发现如果同时添加新字段,可以添加新的元素:
>> 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