flgetl in a loop

5 visualizzazioni (ultimi 30 giorni)
Robbie
Robbie il 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

Risposta accettata

Titus Edelhofer
Titus Edelhofer il 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 Commento
Robbie
Robbie il 29 Nov 2011
Thanks Titus, yes you are right in your assumption and I have got it working now. Robbie

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by