Hi,
I need to read data from a file which consists of approximately 1000 lines of ascii header and then a line consisting of the delimiter "#!" and the data in the file (written in binary data (Int32)). I can read the header using fgetl(fid) and also identify the delimiter, but when trying to continue reading from there using fread(fid,3,'int32') the values are non-sense. Do I somehow loose the reading position?
If I cut the delimiter and the header of the file using a text editor, I can read the purely binary file with fread(fid,3,'int32'). But I would like to speed it up without manually manipulating the file. Any suggestions? Thanks a lot!
So far I'm trying this:
fn='test.nid'; fid = fopen(fn, 'r', 'ieee-be'); stillheader=1; while stillheader % store the current position in file
headerendpos_ascii=ftell(fid); oneline=fgetl(fid); k=k+1; if isempty(strfind(oneline,'#!')) % it's not yet the delimiter
% read relevant data from header ...
else stillheader=0; end end % now read the delimiter and the binary data
fseek(fid,headerendpos_ascii,'bof'); % move to beginning of line with delimiter
test=textscan(fid,'%c',2) % read the delimiter, now we are behind the delimeter #!
binarydata=fread(fid,200,'int32'); % read the first 200 valkues of the binary data.
fclose(fid)
Best Answer