MATLAB: How to extract line numbers of text data

extract line numbersline numbersread line numbers

Hello everyone. I have attached a .txt file (portion.txt) which contains a portion of my data. What I need is to create a script which will identify strings that correspond to pairs of x-y coordinates and return their line numbers. For instance, in the .txt file the first set of coordinates begins at line 3 and ends at line 138 (the number of those pairs is written above each set of coordinates, which at this case is 136). So the script should return those two numbers. Then this process should be done for the whole file. I suppose that the process can be repeated with loop since every next set of coordinates begins after 2 lines from the previous one. How can this be done? Thanks in advance.

Best Answer

str=[]
fid=fopen('portion.txt')
l=fgetl(fid)
while ischar(l)
str{end+1,1}=l;
l=fgetl(fid);
end
fclose(fid)
str
idx=str(cellfun(@numel,regexp(str,'[\d\.]+'))==2)