I am not able to use the same 'VariableNames' argument for "timetable" as for the "table" function.
Here is an example. These two commands run fine and create a table and a timetable with columns named "Date" and "Info".
>> t1 = table(dates, info, 'VariableNames', {'Date', 'Info'});>> tt1 = table2timetable(t1);
But the following command creates an error:
>> tt2 = timetable(dates, info,'VariableNames', {'Date', 'Info'});Error using matlab.internal.tabular.private.tabularDimension/assignLabels (line 365)The VariableNames property must contain one name for each variable in the table.Error in matlab.internal.tabular.private.varNamesDim/validateAndAssignLabels (line 332) obj = obj.assignLabels(newLabels,fullAssignment,varIndices);Error in matlab.internal.tabular.private.tabularDimension/setLabels (line 173) obj = obj.validateAndAssignLabels(newLabels,indices,fullAssignment,... fixDups,fixEmpties,fixIllegal);Error in matlab.internal.tabular.private.tabularDimension/createLike_impl (line 355) obj = obj.setLabels(dimLabels,[]);Error in matlab.internal.tabular.private.varNamesDim/createLike (line 70) obj = obj.createLike_impl(dimLength,dimLabels);Error in tabular/initInternals (line 207) t.varDim = t.varDim.createLike(nvars,varnames); % error if invalid, ...
duplicate, or emptyError in timetable (line 233) t = t.initInternals(vars, numRows, rowtimes, numVars, varnames);
I do not understand the "timetable" failure, since the arguments are identical to the successful "table" constructor call.
Best Answer