Error using fprintf in fopen

2 views (last 30 days)
Surabhi
Surabhi on 3 Mar 2014
Answered: Jos (10584) on 3 Mar 2014
Hi everybody,
I am getting the following error:
Error using fprintf Invalid file identifier. Use fopen to generate a valid file identifier.
Error in LATEST (line 2) fprintf(fid,' Lam Efficiency\n');
while I am ting to execute the following:
fid=fopen('latest.txt','wt'); fprintf(fid,' Lam Efficiency\n');
latest.txt is a text file that I have already created.
Please help

Answers (1)

Jos (10584)
Jos (10584) on 3 Mar 2014
Always check the value of fid after a call to fopen to see if it is valid:
[fid, message] = fopen('latest.txt','wt') ;
if fid == -1,
disp(message)
else
fprintf ...
fclose(fid)
end

Tags

Community Treasure Hunt

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

Start Hunting!