Preserve variable's names and columns with readtable

57 visualizaciones (últimos 30 días)
JMSE
JMSE el 9 de Sept. de 2021
Comentada: JMSE el 23 de Sept. de 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 comentarios
Walter Roberson
Walter Roberson el 9 de Sept. de 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 el 23 de Sept. de 2021
Thank you very much for this help.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by