I am kind of frustrated with fscanf
and its time-performance in reading a file with structured data. I want to read a .txt file, which has three entries per line: DOUBLE DOUBLE LONG-DOUBLE, and I only want to read the first N entries. Unfortunatly, fscanf
is very slow. Do you know any faster method?
Btw, I am aware of several topics on this topic here, for instance this question. However, the answer does not help in my case, as i'm already using fscanf
.
My code is:
formatSpec='%d %d %ld'; % important: last one is long-double to support 64bit values!
sizeA=[3 100000];
file1=fopen('file1.txt','r');
[content,cc]=fscanf(file1,formatSpec,sizeA);
fclose(file1);
Do you know any more clever idea to read N lines of a file with the given structure? Thanks!
Edit: The filecontent of file1.txt
looks like this:
1 1 204378259709308
0 1 204378259782523
1 1 204378260105693
3 1 204378260381676
3 1 204378260854931
1 1 204378261349990
1 1 204378262189528
0 1 204378263067715
1 1 204378263301204
1 1 204378263676471
1 1 204378263771064
1 1 204378264565420
0 1 204378264608240
0 1 204378264973698
...
3 1 205260543966542
So basicly: A[space][space]B[space]C with A and B are [0,9] and C is a 64bit integer