Filter löschen
Filter löschen

flgetl in a loop

3 Ansichten (letzte 30 Tage)
Robbie
Robbie am 29 Nov. 2011
Hi,
I am using the function fgetl embedded in a loop and I want to read a line from a text file each time the loop runs. This works fine for the first iteration however I get an index exceeds Matrix dimensions error when i = 2. Each iteration I want to read the following line in the text file. Here is the code I am using:
for i = 1:(length_file - 1)
% Read the current line from the list file and extract the case numnber
% information from it:
line = fgetl(fid_case(i));
Any suggestions on how to sort this out??
Thanks,
Robbie

Akzeptierte Antwort

Titus Edelhofer
Titus Edelhofer am 29 Nov. 2011
Hi,
I guess fid_case comes from opening the file, i.e. something like
fid_case = fopen('myfile.txt');
If yes, then fid_case is a number denoting the file, no indexing:
line = fgetl(fid_case);
Titus
  1 Kommentar
Robbie
Robbie am 29 Nov. 2011
Thanks Titus, yes you are right in your assumption and I have got it working now. Robbie

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by