MATLAB: Determine the limit of txt file while using regexp

regexptext file

content = fileread( 'trial.txt' ) ;
matches = regexp( content, '[-\d\.]+(?=-\d)', 'match' ) ;
data = str2double( matches );
% With above commands, I extract the specific numeric values in the attached file. But I need to limit this search from %beginning to "START OF RMS MAP" (line 32, but this number is variable) not all lines. How can I set the this last line while I'm using regexp.

Best Answer

It is often faster and easier just to read in all of the data from a file, then then use simple indexing to pick the bits that you need. This will read the first part of the file:
opt = {'CollectOutput',true};
fid = fopen('trial.txt','rt');
C_date = textscan(fid,'%f%f%f%f%f%f%*s',1,'HeaderLines',5,opt{:});
for k = 1:4
C_lat(k,:) = textscan(fid,'%f%f%f%f%f%*s',1,'Delimiter','- ',opt{:});
C_map(k,:) = textscan(fid,repmat('%f',1,16),5,opt{:});
end
fclose(fid);