Preserve variable's names and columns with readtable
58 次查看(过去 30 天)
显示 更早的评论
Hi,
I am facing an minor issue I cannot get my head around; I have been reading csv files with readtable, and it always worked fine. But now I have modified one of the csv files (deleted some lines prior loading it into matlab with readtable), but of course kept the headers and the structure is the same.. And saved it as csv again.
But what happens now while using readtable in order to read the modified csv file is that I am getting this Warning: Table variable names were truncated to the length namelengthmax. The original names are saved in the VariableDescriptions property. And the variables are all saved in one columns only, so it gives a XX * 1 table. I have also tried (...'PreserveVariableNames',true,)
input = 'C:\Users\Judith\Desktop\phd\Data\Hukseflux\Hukseflux_Data_20210713.csv';
output = 'C:\Users\Judith\Desktop\phd\Data\Hukseflux\Calculations\';
data = readtable(input, 'NumHeaderLines', 1, 'Delimiter', ',' ,'DecimalSeparator', '.', "VariableNamingRule" , "preserve")
Many thanks for any help
Judith
2 个评论
Walter Roberson
2021-9-9
Is it possible that there is a double-quote in the first column of the file, and that it is not matched by another " before the comma that is intended to be the delimiter ?
Or is it possible that you had double-quotes in the file, but that your editor "helpfully" replaced them with smart-quotes ?
S = readlines(input);
fprintf('First line as text is:\n');
fprintf('%s\n', S{1});
fprintf('First line character codes are:\n');
charcodes = double(S{1});
disp(charcodes)
if any(charcodes > 127)
fprintf('character codes > 127 detected!\n');
end
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!