MATLAB: Transferring variable names from one table to another

tablevariablenames

I'm trying to use the variable names of one of my tables in another new table, but keep getting an error saying "Error using table The VariableNames property is a cell array of character vectors. To assign multiple variable names, specify names in a string array or a cell array of character vectors" even though I have the variable names saved in a cell array. I have tried making varnames a string array, used a for loop to copy all the names to varnames, concatenated them vertically instead of horizontally just for the heck of it, but I can't seem to figure it out. This is my code:
varnames = cell.empty;
varnames = DataFinal.Properties.VariableNames
T = table('VariableNames',{varnames}, 'RowNames', {'A','B','C'})

Best Answer

varnames = DataFinal.Properties.VariableNames
T = table('VariableNames',varnames, 'RowNames', {'A','B','C'})