MATLAB: How to define an empty table of unknown size

MATLABtablevariabletype

Hi,
I want to define an empty table to fill in a for loop. The size of the table is defined by another variable. How do I define the "VariableType" variable without knowing how many variables there are? In my case they will all be strings. Example:
T = table('Size', [2, numel(Elements)], 'VariableType',["string","string","string","string","string"]);
In this particular cae, numel(Elements) would be 5. But how do I define the table if I don't know numel(Elements) ?

Best Answer

Elements = 1:5;
n = numel(Elements);
T = table('Size', [2 n], 'VariableTypes', repmat("string", 1, n))