필터 지우기
필터 지우기

flgetl in a loop

조회 수: 3 (최근 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