Preserve variable's names and columns with readtable

조회 수: 58 (최근 30일)
JMSE
JMSE 2021년 9월 9일
댓글: JMSE 2021년 9월 23일
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
JMSE
JMSE 2021년 9월 23일
Thank you very much for this help.

댓글을 달려면 로그인하십시오.

답변 (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