MATLAB: Create a table inside a structure

table

I want to create a table inside a structure but I haven't been able to do so with my code
f = struct ('SectionName',{},'SectionID',{},'Measurements',...
table ('MeasName',{},'DateTimeStart',{},'TimeDuration',{},...
'Vehicle',{},'Spped',{},'Direction',{},'Lane',{},'VehPosition',{},...
'Segment',{},'DataLabels',cell ({}),'DataWeighting',cell ({}),...
'DataUnits',cell ({}),'TimeRaw_sec',[],'DataRaw',[]));
Thank you so much if anyone might help

Best Answer

This is not the correct way to create a table array with the specified variable names. The struct function accepts field names and field values as name-value pairs but table does not accept alternating variable names and variable values.
%{
T = table ('MeasName',{},'DateTimeStart',{},'TimeDuration',{},...
'Vehicle',{},'Spped',{},'Direction',{},'Lane',{},'VehPosition',{},...
'Segment',{},'DataLabels',cell ({}),'DataWeighting',cell ({}),...
'DataUnits',cell ({}),'TimeRaw_sec',[],'DataRaw',[]);
%}
You want to specify the 'VariableNames' option to construct this table, and I would additionally specify the 'Size' and 'VariableTypes' options as well. I'm only going to create three variables, but you could create more.
T = table('Size', [2 3], ...
'VariableTypes', {'cell', 'string', 'double'}, ...
'VariableNames', ["C", "S", "D"])
T = 2x3 table
C S D ____________ _________ _ {0×0 double} <missing> 0 {0×0 double} <missing> 0
T{2, "S"} = "abracadabra"
T = 2x3 table
C S D ____________ _____________ _ {0×0 double} <missing> 0 {0×0 double} "abracadabra" 0