how to preserve original column headings (variable names) when using writetable
395 次查看(过去 30 天)
显示 更早的评论
When importing spreadsheets containing invalid variable names, Matlab changes them and stores the original column headings in the VariableDescriptions property of the table. How can I write my table to a file and use the original variable names on export? In other words, how can I export T so that output_table.xlsx is the same as input_table.xlsx?
Reprocessing the exported file as a string is not really an option, because my original file will have multiple sheets.
T = readtable('input_table.xlsx'); % Matlab changes "Column 1" to "Column1"
writetable(T,'output_table.xlsx');
采纳的回答
Sindar
2020-4-22
As of 2019b, table variable names don't need to follow normal variable naming rules. This allows for a couple of fixes:
T = readtable('input_table.xlsx','PreserveVariableNames',true);
or
T.Properties.VariableNames={'Column 1';'Column 2'}
2 个评论
Alan Pawollek
2021-10-15
编辑:Alan Pawollek
2021-10-15
[name of File].Properties.VariableNames
and write it manually for each coloumn.
ps. I habe the latest version of Matlab R2021b
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!