MATLAB: Create a new file

writing to file

>> fid=fopen('firstone.txt''w')
fid =
-1
>> fid=fopen('firstone.txt','w')
fid =
3
>> for i=1:3 fprintf(fid,'The loop variable is %d\n', i) end
ans =
23
ans =
23
ans =
23
>> fclose(fid)
ans =
0
>> while~feof(fid)
aline=fget1(fid)
end
??? Error using ==> feof Invalid file identifier. Use fopen to generate a valid file identifier.
>> fid=fopen('firstone.txt')
fid =
3
>> while~feof(fid)
aline=fget1(fid)
end
??? Undefined function or method 'fget1' for input arguments of type 'double'.
>>
What went wrong and I also wonder if the three answers equal 23 after creating the text means that anything is wrong?

Best Answer

The routine name is fgetl ending with a lower-case L, not fget1 ending with the digit One.
The 23 just means that fprintf() wrote 23 characters to the file.