Importing csv error - incorrectly finalised?

Hi Guys,
R2018a
I have been struggling to import certain *.csv files using readtable(). The files contain a mixture of text and numbers and include some header data followed by a table of actual data.
I guess the files themselves have not been written / finalised correctly by the system that generates the CSVs.
  • If I import the data from an original file, all the heading data is ignored. (see attached screenshot).
  • If I open and save the csv file in excel first ( without changing any of the data or file type ), the data is imported correctly. n.b. the file size changes.
  • When I open and view the files using notepad++ all the delimiters and end of line characters appear identical before and after saving.
I have tried various readtable options such as ('ReadVariableNames',false) and ('DatetimeType','text'). I have also tried detectImportOptions(filename, 'NumHeaderLines', 0), but this did not change the import behaviour.
Any help / insight would be appreciated.
Best regards, MC.
Edit: To be clear, I want to import the entire file. Text and Numbers.
Edit2: It looks like Excel pads the empty columns on save, allowing readtable() to work correctly.

답변 (1개)

HD
HD 2019년 2월 12일

0 개 추천

Data = csvread('Original.csv',7,1);

댓글 수: 2

MC
MC 2019년 2월 12일
Thanks, but this only imports the numbers. I need to import the entire contents of the file.
I have updated question for clarity.
HD
HD 2019년 2월 12일
편집: HD 2019년 2월 12일
i would then suggest to use scantext since different rows have different nuber of columns

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

카테고리

제품

릴리스

R2018a

질문:

MC
2019년 2월 12일

편집:

MC
2019년 2월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by