I a bunch of data structures with an id (id1, id2, id3, ... idN) a single data field that contains variables (var1,var2,var3, ... varK), such that the first structure looks like
id1.data.variable1 = []
id1.data.variable2 = []
.
.
.
All id's share the same data and variable structure.
Now, I would very much like to append a new variable (newvar) to these existing structures in a loop.
For one structure, I would just do this:
id1.data.newvar1 = id1.data.var1^2
which would add newvar1 to my id1.data with id1.data.var1^2 as values.
If i try
for i = 1:length(id_list)
id_list{i}.data.newvar = id_list{i}.data.var1^2
end
I get a "Struct contents reference from a non-struct array object." error.
Any input is appreciated.
id_list{i}as if it were a cell array. The error is because you try to reference the contents of that cell array as if it were a structure. What exactly isid_list? You might want to try(id_list{i})ifid_listis the list of all field names.