reading text file a matrix of string

Hi, i have a large data file in which each row looks like this:
1/1/2012 00:05:00 0.45
all rows have the same format. i want to read it into matlab by using the command "tdfread". it works, but the first 2 columns comes out wrong, the third one is ok.
is there any way to make the command read the first two columns as a string/char and not as a scalar?
using "fopen" takes too long, thats why im trying to use this command.
thank you for your help.

댓글 수: 6

dpb
dpb 2013년 10월 20일
So fast but wrong would be better than right but slow???
What is the delimiter and does the file have a header row that is allowable variable names?
Looks like if those conditions were followed tdfread should do the job. I doubt it'll be any faster than would be textscan or some of the alternatives, however...
Dany
Dany 2013년 10월 20일
i added a header row: date time height
and the delimiter is ' ' (space).
still doesnt work.
i have a text file with at least 105000 rows of data. what do you think would be the faster way to read it and then place the readed data in a matrix.
when i used "fopen" and "fgetl" it took several minutes, its preatty long dont you think?
doc tdfread
"... tdfread(FILENAME,DELIMITER) uses the specified delimiter in place of tabs.
doc textscan % alternatively.
Using fgetl is one record at a time; about as slow a technique as you could choose.
Dany
Dany 2013년 10월 20일
ok thank you. i'll try the "textscan" command, maybe it'll work batter then the "tdfread"
dpb
dpb 2013년 10월 20일
편집: dpb 2013년 10월 20일
Quite likely-- tdfread is an m-file that sucks in the whole file as stream and then tries to figure out what it is that it has read.
textscan otoh is a builtin function that uses a specific format string and the i/o libraries...
Dany
Dany 2013년 10월 20일
it works perfect. thank you

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Text Data Preparation에 대해 자세히 알아보기

제품

질문:

2013년 10월 20일

댓글:

2013년 10월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by