MATLAB: Text file has headers that are 2X4 and are repeated randomly within the data.

headerstext file

txt file is:
R E V D
ms km/h km/h –
689427 0.0 0.00 0.0000
689527 0.0 0.00 0.0000
689627 0.0 0.00 0.0000
689727 0.0 0.00 0.0000
689827 0.0 0.00 0.0000
689927 0.0 0.00 0.0000
690027 0.0 0.00 0.0000
690127 0.0 0.00 0.0000
690227 0.0 0.00 0.0000
headers are repeated randomly across the numerical data. I want to ignore the headers when ever they show up. how would I do that?
the TXT file is about 100000 rows down and 4 columns.
my code is:
result = [];
tic
fid=fopen('MCT_Data.txt');
while 1
tline = fgetl(fid);
if ~ischar(tline), break, end
celldata = textscan(tline,'%f %f %f %f %f %f');
matdata = cell2mat(celldata);
% match fails for text lines, textscan returns empty cells
result = [result ; matdata];
end
toc
fclose(fid);

Best Answer

str = fileread('MCT_Data.txt');
nums = cellfun(@str2double, regexp(str, '([\d.,]+)', 'match'));
x = reshape(nums, 4, [])'
x =
689427 0 0 0
689527 0 0 0
689627 0 0 0
689727 0 0 0
689827 0 0 0
689927 0 0 0
690027 0 0 0
690127 0 0 0
690227 0 0 0