Think of fid as a pointer that tells textscan where to read from. It moves its way byte by byte through the file until it reaches the end. When you call textscan for Headerlin1, it's at the end of the file. Your option, then, is to either read in Headerlin1 first, and then continue with reading in the rest of the file, or use frewind to bring fid back to the beginning of the file before reading in the first line. You can get textscan to skip the text before a number by placing that text right before the format spec: Lat:%f
Option 1
fid=fopen('aa__file002.txt');
Headerlin1 = textscan(fid,'Lat:%f Lon:%f %*[^\n]','Delimiter',',');
A = textscan(fid,'%s %s %f','HeaderLines',5);
fclose(fid);
Option 2
fid=fopen('aa__file002.txt');
A = textscan(fid,'%s %s %f','HeaderLines',6);
frewind(fid);
Headerlin1 = textscan(fid,'Lat:%f Lon:%f','Delimiter',',');
fclose(fid);
Best Answer