How to import some large data please

조회 수: 2 (최근 30일)
Mate 2u
Mate 2u 2013년 12월 24일
댓글: Mate 2u 2014년 1월 5일
Hi all I have a file called DJ.csv which has 5 columns. 1) Dates (01/02/2007), 2) Times (30.42.0), 3) prices 12553, 12442, 4) Codes (DJ123) and 5) trade size.
I want to take column 3 and 5 (price and trade size into matlab). I am having some trouble as the csv is quite big.
I tried this:
fileID = fopen('K:\test\test\DJ.csv');
A = fread(fileID,'double');
fclose(fileID);
But it only gives me a vector of values which are not the same as my data. Any help would be very much appreciated.
Thanks.
  댓글 수: 1
Mate 2u
Mate 2u 2013년 12월 24일
As a note, importdata works, but it is not suitable for very large files.

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

채택된 답변

dpb
dpb 2013년 12월 25일
편집: dpb 2013년 12월 26일
fread is for stream unformatted files; you have formatted delimited file--
doc textscan % and friends
If you really only want/need the two columns sotoo (air-code, untested)
[p,s]=textread('K:\test\test\DJ.csv','%*s%*s,%f%*f%f','delimiter',',');
ought to do unless the third column is indeed a comma-for-a-decimal point as well as a comma-delimited file. In that case you've got a problem. You'll have to read three values instead of just two or preprocess the file or otherwise handle the decimal separator as Matlab can't (and you can't expect it to) know the difference between comma-delimiters and decimal places.
  댓글 수: 7
Walter Roberson
Walter Roberson 2014년 1월 3일
datacell = textscan(fid,'%*s%*s%f%*s%f','delimiter',',');
The previous version had a stray comma in the format.
Mate 2u
Mate 2u 2014년 1월 5일
Thank you, worked well.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by