Below I have a snippet of code that I am using to create a structure with field names that are defined in the array 'field_names'. This seems like a very clunky way of creating the structure.
Is there a better way that I can do this in one line? Perhaps there is some syntax trick to help me avoid the for loop?
%array of names to create field names from
field_names = ['num1', 'num2', 'num3', 'etc'];
data = struct()
for i = 1:length(field_names)
data.field_names(i) = rand() %some random value, doesn't matter for now
end