MATLAB: Reading data from .txt file skipping lines and others

headerlinesoptimizationtextscan

Hello everyone!
I am findig trouble reading the data from the file attached. I have tried to read the instance name using textscan, but I couldn't. I have tried to skip the first four lines using the HeaderLines option, and then I succesfully could read the first two numbers, but then I found errors again. I am kind of new at this. Would you help me out? I would really appreciate it 🙂
have a good day!
Fede

Best Answer

Try
fid = fopen( 'rc204afixed.txt' );
ca1 = textscan( fid, '', 'Headerlines', 4, 'CollectOutput',true );
ca2 = textscan( fid, '', 'Headerlines', 2, 'CollectOutput',true );
ca3 = textscan( fid, '', 'Headerlines', 4, 'CollectOutput',true );
fclose( fid );
inpect the result
>> ca3{1}
ans =
0 1 100000000 0
1 100 150 14
2 200 350 2
3 300 5500 0
4 400 8000 0
5 500 11000 0
6 1000 25000 0
" ... and stops when it cannot match formatSpec to the data ... . If you resume a text scan of a file by calling textscan with the same file identifier (fileID), then textscan automatically resumes reading at the point where it terminated the last read."
formatSpec = '' is an undocumented feature. It's interpreted as the number of %f needed to read a row.