Using textscan with multiple input formats

I've been having trouble getting textscan to read a .csv file with integers, dates, and floats. The .csv is in this format (actual file attached):
1,00:00:00:00,21.772,21.418,22.028,21.564
2,00:00:00:10,21.792,21.444,22.038,21.57
3,00:00:00:19,21.798,21.444,22.045,21.579
The code I currently have is:
fid = fopen('test.csv');
raw = textscan(fid,'%u %{DD:HH:mm:ss}D %f %f %f %f','Delimiter',',','HeaderLines',5);
fclose(fid);
For some reason, this is giving me a 1x6 cell array of empty matrices, and no error messages.
Thanks in advance!

댓글 수: 2

per isakson
per isakson 2015년 6월 26일
편집: per isakson 2015년 6월 26일
Your code requires a recent release of Matlab. Which do you use?
With R2013b
>> cac = textscan( '3,00:00:00:19,21.798,21.444,22.045,21.579' ...
, '%u%u%u%u%u%f%f%f%f', 'Delimiter',{':',','})
cac =
[3] [0] [0] [0] [19] [21.7980] [21.4440] [22.0450] [21.5790]
Billy Montana
Billy Montana 2015년 6월 26일
편집: Billy Montana 2015년 6월 26일
I use R2014b, so I don't think that's a problem.
I figured out the problem - the file was named test.csv, but for some reason it was encoded as a .txt file. I resaved the file as .csv and it works now.
Also, thanks for the idea to not use datetimes for measuring time - it will be much easier to just calculate it.

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

태그

질문:

2015년 6월 25일

편집:

2015년 6월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by