fopen and fget reading lines from a text
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sergio
am 2 Feb. 2024
Kommentiert: Stephen23
am 2 Feb. 2024
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 Kommentare
Akzeptierte Antwort
Dyuman Joshi
am 2 Feb. 2024
Bearbeitet: Dyuman Joshi
am 2 Feb. 2024
3 Kommentare
Dyuman Joshi
am 2 Feb. 2024
Okay.
But it's not a good idea to hard code values. Better to store it as a variable and use it accordingly.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Text Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!