Transferring variable names from one table to another

31 vues (au cours des 30 derniers jours)
Kanak Gupta
Kanak Gupta le 14 Août 2020
Commenté : Walter Roberson le 25 Août 2022
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'})

Réponse acceptée

Walter Roberson
Walter Roberson le 14 Août 2020
varnames = DataFinal.Properties.VariableNames
T = table('VariableNames',varnames, 'RowNames', {'A','B','C'})
  8 commentaires
Jonathan Thompson
Jonathan Thompson le 24 Août 2022
Thanks. It seems that the use of repmat only allows one data type. I suppose that if I need to have columns of different data types, I can just change those columns after the table is created, right?
Walter Roberson
Walter Roberson le 25 Août 2022
repelem({'double', 'categorical', 'double'}, 1, [17, 2, 11])
for example for the case of 17 double followed by 2 categorical followed by 11 double

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by