reading specific lines from a .txt file

조회 수: 24 (최근 30일)
Joseph Kutteh
Joseph Kutteh 2021년 6월 30일
댓글: Joseph Kutteh 2021년 6월 30일
hello,
if i have a .txt file how can i read specific lines from this file? for example, say my file looks like this:
1
2
3
4
5
...
100
listing numbers 1-100, 1 column, 100 rows. how can i read lines 10-15 and only print the numbers on those lines
thank you
i am using matlab R2019b

채택된 답변

Yazan
Yazan 2021년 6월 30일
Use readmatrix and specify the 'Range' option. Assuming that you have a one-column txt file, you can use the following:
A = readmatrix('yourtxtFileName', 'FileType', 'text', 'Range', [firstRow, 1, lastRow, 1])
  댓글 수: 1
Joseph Kutteh
Joseph Kutteh 2021년 6월 30일
thank you very much! it works perfectly

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by