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
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 CenterFile Exchange 中查找有关 File Operations 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by