MATLAB: Am I having trouble reading an ascii file in notepad that I produced using FPRINTF

\tasciieditorfopenMATLABmodenotepadpadrttext;wordwt

Why am I having trouble reading an ascii file in notepad that I produced using FPRINTF?
I am using the following code:
fid=fopen('out.txt','w');
fprintf(fid,'%i\n',3);
fclose(fid)

Best Answer

Using the following syntax will open the file in text mode, allowing it to be read in notepad:
fid=fopen('out.txt','wt');
fprintf(fid,'%i\n',3);
fclose(fid)
This is because of the "t" flag in the FOPEN statement. Without the "t" flag, the ascii file produced will only print one newline character, while PC standard ASCII files expect two different characters, '/r/n'.
This can be demonstrated by the fact that the following syntax also works:
fid=fopen('out.txt','w');
fprintf(fid,'%i\r\n',3);
fclose(fid)
For more information on the FOPEN function, see: