Using fgetl() to read lines

21 Ansichten (letzte 30 Tage)
ZK
ZK am 10 Jan. 2013
How can I choose different line to read instead first line, using fgetl() formula?
Thank you.

Akzeptierte Antwort

Amith Kamath
Amith Kamath am 10 Jan. 2013
http://www.mathworks.com/matlabcentral/newsreader/view_thread/297814 may be of some help. Unless you are constrained to using fgetl() for some reason,
C = textscan(fid, '%s','delimiter', '\n');
% Setup the line number in LineNum,
RelevantLine=C{1}{Linenum};
should do the trick.
  3 Kommentare
Amith Kamath
Amith Kamath am 11 Jan. 2013
I agree with Walter that this stores the entire file into the cell array, and isn't technically skipping lines. You could possibly choose more lines by using strcat on C{1}{LineNum1} and C{1}{LineNum2}.
ZK
ZK am 11 Jan. 2013
Bearbeitet: ZK am 11 Jan. 2013
Thank You I will remember that.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 10 Jan. 2013
There is no method at the operating system level to position by line. The operating system itself uses fgetl() (or fgets()) to move forward by lines. MATLAB does not provide any "wrapper" over fgetl() to support skipping lines.

Kategorien

Mehr zu Entering Commands finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by