Reading character data from .txt file to print statement

1 vue (au cours des 30 derniers jours)
Emily Anderson
Emily Anderson le 22 Sep 2020
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.

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Data Import and Export dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by