0
votes

Need to create Empty Table of given size using Variable Type and Variable Names using official documentation gives me error in Matlab 2016 for example:

sz = [4 3];
varTypes = {'double','datetime','string'};
T = table('Size',sz,'VariableTypes',varTypes)

gives following error:

Caused by: You may have intended to create a table with one row from one or more variables that are character strings. Consider using cell arrays of strings rather than character arrays. Alternatively, create a cell array with one row, and convert that to a table using CELL2TABLE.

1
I've assumed that you're using R2016b since you mentioned only 2016 and string arrays, the use of which is suggested in the error message, were introduced in R2016b - Sardar Usama

1 Answers

2
votes

The full error message is this:

Error using table (line 281)
Invalid parameter name: Size.
Caused by:
You may have intended to create a table with one row from one or more variables that are character strings. Consider using cell arrays of strings rather than character arrays. Alternatively, create a cell array with one row, and convert that to a table using CELL2TABLE.

As the error message indicates, the parameter 'Size' didn't exist in R2016b. The parameter 'VariableTypes' also didn't exist back then. Both are introduced in R2018a.

The same result can be replicated in ≥ R2016b using the hint given in the error message as follows:

T = cell2table(repmat({0, NaT, string(NaN)}, 4, 1));

String arrays were introduced in R2016b. In versions older than that, you can use character arrays.