MATLAB: Loop to extract set of rows for .txt file

acessing set of rowparsing

Hello,
I want to read attached "text.txt" file
here I want to skip first 5 line,
then I want to access set of 4 line in a loop, till end of file

Best Answer

hdr = {};
num = {};
[fid,msg] = fopen('text.txt','rt');
% Ignore first five lines:
for k = 1:5
fgetl(fid);
end
% Read groups of four lines:
while ~feof(fid)
str = fgetl(fid);
if numel(str)>3
hdr{end+1} = str;
str = [fgets(fid),fgets(fid),fgets(fid)];
num{end+1} = sscanf(str,'%f');
end
end
fclose(fid);
For example, the first group of four lines:
>> hdr{1}
ans = alphanso1 Mumbai s1 50.000 150.000 500.000 1
>> num{1}
ans =
2.5694e+000
-8.5974e-005
4.1948e-008
-1.0018e-011
1.2283e-015
2.0000e+000
2.9218e+004
4.7843e+000
3.1683e+000
-3.2793e-003
6.6431e-006
3.0000e+000
-6.1281e-009
2.1127e-012
2.9122e+004
2.0519e+000
4.0000e+000