MATLAB: Secify what is the end of a line using textscan

end of linesendoflinesheaderlinestextscan

I have a .dat file with varied spacing between a series of numbers. I want to be able to jump to any one of these numbers using textscan with its 'headerlines' feature. The problem is, I need to specify that each separate number should be a new line. That way if is use 'headerlines',2 in textscan it will skip the first two numbers and go from there.
My .dat file starts like this
1 55 63 78 45.6 34.6 45.7 23.5 23.7 34.5 23.6 ...
how can I make textscan see line one as 1… line two as 55… line three as 63… line four as 78 etc? I know about the 'EndOfLine' feature and have tried everything with that but it's still not giving me what I need.
Thanks
-Kyle

Best Answer

I would not do it that way. What I would do is something like:
fid = fopen(YourFileName, 'rt');
wantpos = 3; %want 3rd number
fmt = [repmat('%*f', 1, wantpos-1), '%f'];
datacell = textscan(fid, fmt, 1);
wantednum = datacell{1};
fclose(fid);
This can be used even if you have fewer numbers per line than "wantpos": it will read as many lines as it needs to in order to get the proper number.
Afterwards the file will be positioned right after the number that was read.
Related Question