Reading character data from .txt file to print statement

1 view (last 30 days)
I have this data in a text file:
0 TIROS 6
1 397U 62047A 20244.94764729 -.00000082 00000-0 14494-4 0 9995
2 397 58.3053 89.8562 0014872 107.0981 253.1694 14.88472429118167
0 VANGUARD 2
1 11U 59001A 20245.13463223 -.00000044 00000-0 -34477-4 0 9993
2 11 32.8740 131.2419 1468349 318.6787 31.1316 11.85682505625700
0 POLAR BEAR
1 17070U 86088A 20245.12580324 .00000060 00000-0 51032-4 0 9994
2 17070 89.5272 268.9063 0039092 172.4409 247.9550 13.74805603695047
I want to make an fprintf statement that calls the titles "TIROS 6", "VANGUARD 2", and "POLAR BEAR" from the text file and reads them into the print statement.

Accepted Answer

Walter Roberson
Walter Roberson on 22 Sep 2020
S = fileread('YourFile.txt');
titlelines = regexp(S, '^0\s+(.*)$', 'match', 'dotexceptnewline', 'lineanchors');
fprintf('%s\n', titlelines{:});

More Answers (0)

Categories

Find more on Data Import and Export in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!