fopen and fget reading lines from a text
조회 수: 7 (최근 30일)
이전 댓글 표시
Hi, I try to work with fget and fopen, and I would like to read the first three lines from a text file (attached), and print them on the MATLAB output,
I try
fid = fopen('test.txt');
line_ex = fgetl(5) % read line excluding newline character
fid = fopen('test.txt');
line_ex = fgetl(5) % read line excluding newline character
fid = fopen('test.txt');
line_ex = fgetl(5) % read line excluding newline character
However, this prints out only the three first lines one time, then it continues to 4,5,6, then 7,8,9 etc.
Is there a better way to simply reproduce the three first lines of the text files, with the same command, over again?
Thanks
댓글 수: 0
채택된 답변
Dyuman Joshi
2024년 2월 2일
편집: Dyuman Joshi
2024년 2월 2일
댓글 수: 3
Dyuman Joshi
2024년 2월 2일
Okay.
But it's not a good idea to hard code values. Better to store it as a variable and use it accordingly.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!