MATLAB: Help on creating structures?

structurestructures

The only way I know how to create a structure where all of my sections are ordered is like so:
struct1(1).name='Krista';
struct1(2).name='Kranthi';
struct1(3).name='Kevin';
struct1(4).name='Kalil';
struct1(5).name='Kristen';
struct1(1).date=[10 5 1993];
struct1(2).date=[6 16 1990];
struct1(3).date=[4 20 1991];
struct1(4).date=[7 10 1819];
struct1(5).date=[2 31 1992];
Is there are more concise way to write the code for this and still get the same result?? Help appreciated 🙂 thank you!

Best Answer

You could enter your data into a two-column cell array and then use CELL2STRUCT:
data = {'Krista', [10 5 1993]; ...
'Kranthi', [6 16 1990]; ...
'Kevin', [4 20 1991]; ...
'Kalil', [7 10 1819]; ...
'Kristen', [2 31 1992]};
s = cell2struct(data, {'name', 'date'},2)