필터 지우기
필터 지우기

Textscan doesn't work in reading csv files

조회 수: 3 (최근 30일)
BR
BR 2017년 10월 27일
댓글: Cam Salzberger 2017년 10월 27일
I have a very large csv file with strings and Numeric values all together in it. The number of rows in the file exceeds more than 2 million. So, I can't even open in Excel. I tried using the following format
fileID = fopen('IBM.FullDepth.20140128.csv');
C = textscan(fileID,'%f %f %f %s %s %f %f %s %s');
fclose(fileID);
but the returned value of cell 'C' is empty. And I can't upload the file, since the size is too big please help.
Thanks

채택된 답변

Star Strider
Star Strider 2017년 10월 27일
If you have R2013b or later, use the readtable (link) function.
Otherwise, see if you can read it with the xlsread (link) function.
  댓글 수: 3
Star Strider
Star Strider 2017년 10월 27일
As always, my pleasure!
The readtable function uses whatever it needs to import your data. To the best of my knowledge, neither readtable nor xlsread require (or even accept) format descriptors.
Cam Salzberger
Cam Salzberger 2017년 10월 27일
readtable will accept an optional 'Format' argument, but it is not necessary.
xlsread is for use on Microsoft Excel files. A CSV file is simply a text file with (most-commonly) comma-separated values. It is not an Excel file, despite Excel being a very common program used to open that type of file. xlsread will not work for CSV files when in basic mode at least (i.e. on non-Windows platforms, or if Excel is not installed).
csvread and dlmread are options for CSV files, but only work for numeric-data.
If you are reading a CSV with non-numeric data file pre-R2013b, you can always use fileread to just get the text at once, then parse it separately. Or do low-level file reading, as you tried with textscan.
-Cam

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by