MATLAB: Error: Undefined function or variable ‘fgetl’ when fgetl() is placed inside an else statement

errorMATLAB

Hi, I'm writing a simple script to read a .csv file. I get the error:
Undefined function or variable 'fgetl'.
Error in (filename) (line 36)
line = fgetl(fid);"
It's strange because the call to fgetl() outside the if statement works fine!
if(~exist(file_in))
FInputErrMsg = 'not located in working directory.';
Suggestion = ['Change script parameter or move the file into script'...
' working directory.'];
error('Expected input file: "%s" %s\n%s',file_in,FInputErrMsg,Suggestion);
elseif(exist(file_out))
% TODO#1
end
% Open file_in1 to count the number of sites N
fid = fopen(file_in,'r');
line = fgetl(fid);
if(fid == -1)
error('Error opening %s. Exiting.', file_in);
else
line = fget1(fid); %<---------------------- Offending Line
end
fclose(fid);

Best Answer

Check in your original code whether you're calling fgetl with a lower-case L or calling fget1 with the number one. The code segment you posted implies the latter, the error message you posted implies the former.