|
On 5/25/2012 3:17 PM, Jameson wrote:
...
> I would like to either open the file whenever I need to read, and then
> jump to the line or lines that I would like to read in, and begin there.
> I haven't found an easy way to do this in matlab yet without reading in
> the first N lines and just throwing them out...
...
Well, the thing about sequential files is that they're well, "sequential".
If they are of fixed length records you can use fseek to move the file
pointer so many bytes and then fscanf() or fgetl() from there, but if
they're variable length then you have a problem in knowing for certain
you got the right number of records unless you have a timestamp or other
identifying data in the record of choice.
If they're not terribly large, another alternative that could
potentially be faster would be to use fread() instead on chunks (or the
whole file) and then do things like search for the nth \n in memory to
get to the right place and then process in memory.
All in all, if you want random-access files you'll need to create the
files in a form that supports such things or a database structure
instead of flat files.
--
|