MATLAB: How to read the text files with the format “13.07.201​3,00:00:00​,0044,918,​47,200,093​0,019,23,9​,0178,75,6​3, +RA, R+,03041,0​2059,0,06,​SPECTRUM,,​,,,,,001,,​,,,,,,,,,,​,,,,,,,,,,​,,,,,,003,​001,001,,,​001,,001,,​,,,,,,,,,,​,,,,,,,,,,​,,,,002,,0

file with different format

How I can read text file with the following format
13.07.2013,00:00:00,0044,918,47,200,0930,019,23,9,0178,75,63, +RA, R+,03041,02059,0,06,<SPECTRUM>,,,,,,,001,,,,,,,,,,,,,,,,,,,,,,,,,,,,003,001,001,,,001,,001,,,,,,,,,,,,,,,,,,,,,,,,,,002,,001,001,,001,,,,,,,,,,,,,,,,,,,,,,,,,,001,,,,001,,,,,,,,,,,,,,,,,,,,,,,,,,,,,002,001,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,001,001,,,001,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,001,,,,,,,,,,,,,,,,,,,,,,,,001,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,001,003,,002,001,,,,,001,,,,,,,,,,,,,,,,,,,,,,,,003,003,001,002,001,,,,,,,,,,,,,,,,,,,,,,,,,,,003,007,006,001,002,001,001,,,,,,,,,,,,,,,,,,,,,,,,,,006,011,004,002,004,,002,,,,,,,,,,,,,,,,,,,,,,,,,,007,017,004,005,,003,,,,,,,,,,,,,,,,,,,,,,,,,,,017,017,005,003,002,002,,,001,001,,,,,,,,,,,,,,,,,,,,,,,032,051,024,014,007,007,002,001,,001,,,,,,,,,,,,,,,,,,,,,,,026,046,032,018,009,003,002,001,,,,,,,,,,,,,,,,,,,,,,,,,039,063,038,021,010,005,002,001,002,001,,,001,,,,,,,,,,,,,,,,,,,,020,031,027,015,012,008,001,,,001,001,,,,,,,,,,,,,,,,,,,,,,083,073,054,037,017,008,005,007,004,001,,,,,,,,,,,,,,,,,,,,,,,131,172,126,087,067,054,029,025,020,005,001,001,,,001,,,,,,,,,,,,,,,,,,145,158,091,066,045,033,048,049,051,029,004,002,,,,,,,,,,,,,,,,,,,,,058,072,058,070,071,068,046,040,054,031,021,009,001,,,,,,,,,,,,,,,,,,,,,002,002,004,004,008,033,034,048,019,029,014,004,,,,,,,,,,,,,,,,,,,,,,,001,,,,001,020,019,020,011,012,005,002,,,,,,,,,,,,,,,,,,,,,,,,,,001,013,036,036,026,024,009,,,,,,,,,,,,,,,,,,,,,,,,,,,,002,022,021,026,017,011,003,001,,,,,,,,,,,,,,,,,,,,,,,,,,,001,014,012,009,001,001,002,,,,,,,,,,,,,,,,,,,,,,,,,,,003,009,005,006,,001,,,,,,,,,,,,,,,,,,,,,,,,,,,,001,003,001,,001,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,</SPECTRUM>
and I need to read the "<SPECTRUM>, ,,….,</SPECTRUM> into a single variable

Best Answer

S = fileread('NameOfTextFile');
spectrums = regexp(S, '(?<=<SPECTRUM>).*?(?=</SPECTRUM>)', 'match');
There will now be a cell array of character vectors with one inside of a <SPECTRUM>...</SPECTRUM> per element.