flgetl in a loop

5 次查看(过去 30 天)
Robbie
Robbie 2011-11-29
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

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by