How to add a new element to the structure array? I cannot connect to an empty structure:
>> 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.
So, is it possible to add a new element with empty fields?
UPDATE
I found that I can add a new element if I add a new field at the same time:
>> 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
It is incredible that there is no direct way! Maybe there are a few colon equivalents for structures?
source share