Preserve variable's names and columns with readtable

58 Ansichten (letzte 30 Tage)
JMSE
JMSE am 9 Sep. 2021
Kommentiert: JMSE am 23 Sep. 2021
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 Kommentare
Walter Roberson
Walter Roberson am 9 Sep. 2021
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
JMSE
JMSE am 23 Sep. 2021
Thank you very much for this help.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by