Error using fprintf Invalid file identifier. Use fopen to generate a valid file identifier.
12 views (last 30 days)
Show older comments
Hi everyone, am getting this error message and i don't know how to fix it.
B = [STR_DATE,num2str(lon),num2str(lat),STR_DUR];
gn=sprintf('events/%s/%s',DUR_NAME,STR_DATE);
fid2 = fopen(gn,'wt');
fprintf(fid2,'%10.2f %10.2f %10.2f %10.2f \r\n',B');
fclose(fid2);
this is how i used the fprintf function.
7 Comments
Answers (2)
Adam Danz
on 12 Jul 2018
If fopen cannot open the file, it returns -1. If the value of your 'fid2' is not -1, respond to this answer in the comment section and we can dig deeper.
Check that your file can be found, is not protected, and is accessible.
0 Comments
See Also
Categories
Find more on Database Toolbox 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!