I am trying to preallocate an array of structures but without knowing which fields are contained in the structure. Is there a way to preallocate a 1x4 struct
without knowing how much fields it will contain ?
Following many previous questions here and here the way to preallocate an array of structure, knowing the fields would be :
N = 10;
struct_array = struct('x',cell(1,N),'y',cell(1,N));
for i = 1:N
a.x = i*i;
a.y = num2str(i+i);
struct_array(i) = a;
end