Trouble with textscan and large .dat files
조회 수: 3 (최근 30일)
이전 댓글 표시
I am trying to import specific values from a very large .dat file (use dummy.dat).
These values are in a single column, that is extremely long (700000 rows). I am trying to pick out specific values within this column and then move on without importing the whole column.
When I use
A = importdata('dummy.dat')
I get a nice [700000x 1] array in my workspace, so that works but again, I don't want to take the time to import the whole thing.
When I use
fid=fopen('dummy.dat');
A = textscan(fid,%f,'delimiter','')
I get a 1 x 1 cell in which the cell is a [700000 x 1] double, so that works, but I am still importing the whole thing.
Say I want to pick out the number that is in the 5th row, and only that number. I am trying:
fid=fopen('dummy.dat');
A = textscan(fid,%f,1,'delimiter','','headerlines',4)
For some reason, when I do this, the single column nature of the .dat file is changed into 4 columns so instead of reading
1
2
3
4
5
6...
I get
1 2 3 4
5 6 ...
Which is screwing up my rows and headerlines and what values I am reading.
Anyone know whats going on here?
Thanks.
댓글 수: 1
Walter Roberson
2013년 5월 8일
What is your intention in setting the delimiter to '' ? Why not just leave the delimiter unspecified ?
채택된 답변
Walter Roberson
2013년 5월 8일
If you are importing the same file multiple times, I suggest reading it once and writing a version of it in binary. Then, each time you want to read, knowing which position you want to start at, you can fseek() to the (position - 1) * (the size in bytes of a single entry) and fread() from there.
추가 답변 (1개)
Gabriel
2013년 6월 11일
If you don't care about speed at all, The easiest way is to use fgetl to read each line, then textscan on each line to grab what you want. Slow but easy.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Low-Level File I/O에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!