MATLAB: How to turn data between ‘#’ into individual matrices

dlmreadtextscan

A fortran model outputs the following text files :
#
#
# done by Task#2 of TABOO on 2017.02.23 time=15.15.13
# Observer longitude (deg) = 145.0100
# Observer colatitude (deg) = 27.0000
#
# Time u_rad u_col u_lon geoid mass
# (kyrs) (m) (m) (m) (m) (kg)
# --------------------------------------------------------------
0.0000 -82.6972 -0.0055 1.4561 -3.2293 0.00000E+00
1.0000 -23.2048 -0.0012 0.3021 -1.1764 0.00000E+00
2.0000 -8.3823 -0.0003 0.0797 -0.5409 0.00000E+00
3.0000 -3.6872 -0.0001 0.0266 -0.2891 0.00000E+00
4.0000 -1.9649 -0.0000 0.0114 -0.1737 0.00000E+00
5.0000 -1.2411 -0.0000 0.0063 -0.1141 0.00000E+00
6.0000 -0.8946 -0.0000 0.0043 -0.0802 0.00000E+00
7.0000 -0.7080 -0.0000 0.0034 -0.0594 0.00000E+00
8.0000 -0.5971 -0.0000 0.0029 -0.0459 0.00000E+00
9.0000 -0.5257 -0.0000 0.0025 -0.0368 0.00000E+00
10.0000 -0.4765 -0.0000 0.0023 -0.0304 0.00000E+00
#
#
# done by Task#2 of TABOO on 2017.02.23 time=15.15.13
# Observer longitude (deg) = 146.2500
# Observer colatitude (deg) = 27.0000
#
# Time u_rad u_col u_lon geoid mass
# (kyrs) (m) (m) (m) (m) (kg)
# --------------------------------------------------------------
0.0000 -82.0875 -0.0129 -2.2170 -3.2158 0.00000E+00
1.0000 -23.0922 -0.0027 -0.4604 -1.1733 0.00000E+00
2.0000 -8.3553 -0.0007 -0.1216 -0.5401 0.00000E+00
3.0000 -3.6796 -0.0002 -0.0406 -0.2888 0.00000E+00
4.0000 -1.9625 -0.0001 -0.0174 -0.1736 0.00000E+00
5.0000 -1.2402 -0.0001 -0.0097 -0.1140 0.00000E+00
6.0000 -0.8941 -0.0000 -0.0066 -0.0802 0.00000E+00
7.0000 -0.7077 -0.0000 -0.0052 -0.0594 0.00000E+00
8.0000 -0.5969 -0.0000 -0.0044 -0.0459 0.00000E+00
9.0000 -0.5255 -0.0000 -0.0039 -0.0368 0.00000E+00
10.0000 -0.4763 -0.0000 -0.0036 -0.0304 0.00000E+00
#
#
# done by Task#2 of TABOO on 2017.02.23 time=15.15.13
# Observer longitude (deg) = 147.0000
# Observer colatitude (deg) = 27.0000
I need to write a function which turns each section which does not begin with '#' into its own respective matrix or cell array. dlmread and textscan do not work well.

Best Answer

fid = fopen('your txt file') ;
S = textscan(fid,'%s','delimiter','\n') ;
fclose(fid) ;
S = S{1} ;
%%get locations where # not present
idx = strfind(S, '#');
idx = find((cellfun('isempty',idx)));
%%get indices where # breaks
% iwant = S(idx) ;
iwant = cell2mat(cellfun(@str2num,S(idx),'un',0)) ;