How to import a 50mb csv file?

조회 수: 5 (최근 30일)
Stef
Stef 2018년 6월 27일
댓글: Walter Roberson 2018년 6월 27일
I have a csv file of size 50mb. The data is numbers and strings. I tried to import it using the import button in matlab. Now the data is 100% parsed but nothing happens for an hour, I think it's still working. It took more than 6 hours to parse 100%. Is there a smarter and faster way to import the data and save it as a matrix?

답변 (1개)

Walter Roberson
Walter Roberson 2018년 6월 27일
We recommend using readtable(). Especially if you have R2016b or later, in which case use detectImportOptions first to create an options structure to pass to readtable() .
  댓글 수: 2
Stef
Stef 2018년 6월 27일
Thank you, readtable works. But I need to end up with a matrix, but table2array does not work. Do you have an idea how to solve that?
Walter Roberson
Walter Roberson 2018년 6월 27일
If you need to end up with a matrix, then table2cell() . You cannot use table2array() because you have mixed data types.
If you want to create arrays of the various parts that are alike, then
raw = table2cell(YourTable);
mask = cellfun(@isnumeric, raw(1,:));
num = cell2mat( raw(:,mask) );
mask = cellfun(@ischar, raw(1,:));
txt = raw(:,mask);
Here I make the assumption that all entries in a column are the same data type. This will not necessarily be true if you used readtable() with empty cells or text-based indicators of missing data such as "NA" that do not happen to match "nan" or "NaN" -- though if you used detectImportOptions then it should notice those by itself, and you can also use the TreatAsEmpty option to readtable.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by