'Invalid file identifier' while trying to write to a file (in Windows 7)
Show older comments
Ive written a program that can save a mesh plot as a .obj file so it can be imported in a 3D program such as blender. It worked perfectly a couple of hours ago, but after i closed matblab and started it again it keeps giving me an error everytime it has to write the file.
I'm pretty sure the solution to this problem has to be quite simple, but after looking for it on the internet for almost my entire evening now (without any results so far) ive descided to post it on here...
At the moment ive written another program that only tests the 'writing function'. It should simply create the array [1, 2, 3, 4, 5] and write the first 3 elements to the file graph.obj. Here's what i did:
clear all;
X = 1:5;
status = fclose('all')
[fid, message] = fopen('graph.obj','w')
fprintf(fid, 'write-test %f %f %f \n', X(1), X(2), X(3));
fclose(fid);
The problem is i'm getting the following errors:
status = 0
fid = -1
message = permission denied
??? Error using ==> fprintf
Invalid file identifier. Use fopen to generate a valif file identifier.
Error in ==> frpintf(fid, 'write-test %f %f %f \n', X(1), X(2), X(3));
I use the fclose('all') to close all open streams in case any one is acidentally open. The satus gives me 0, so no errors seem to have occured while closing them. I also dont have the file opened in some other program or somwehre else.
The file graph.obj is in te same directory (the MATLAB directory in My Documents (im using Windows 7)) as the script itself is in. I made sure the file graph.obj is NOT set to 'read only' (ive created the file myself to be sure it exists).
I really don't know what it can be... and i really don't get why it all did work before i closed matlab.
Hope someone can help me out :)
Accepted Answer
More Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!