Reading character data from .txt file to print statement

조회 수: 1 (최근 30일)
Emily Anderson
Emily Anderson 2020년 9월 22일
답변: Walter Roberson 2020년 9월 22일
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.

채택된 답변

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by