flgetl in a loop

5 visualizaciones (últimos 30 días)
Robbie
Robbie el 29 de Nov. de 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

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by