How to use fprintf in Matlab R2016a
Show older comments
I am working with Matlab R2016a, and I get error for the follwing code which is form mathworks's website.
The thing is whenever I use fprintf, I get the same error.
Thanks a lot for the help.
x = 0:.1:1;
A = [x; exp(x)];
fileID = fopen('exp.txt','w');
fprintf(fileID,'%6s %12s\n','x','exp(x)');
fprintf(fileID,'%6.2f %12.8f\n',A);
fclose(fileID);
Error:
Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in Untitled (line 5)
fprintf(fileID,'%6s %12s\n','x','exp(x)');
Accepted Answer
More Answers (1)
Jos (10584)
on 9 Jun 2016
2 votes
The problem is with fopen. Did you check the value of fileID?
Most likely, you do not have the permission to write in the current folder.
1 Comment
Categories
Find more on Downloads in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!