I am using Matlab to create a new file by calling
fid = fopen(filename,'w')
since filename doesn't exist, it should create a new file and give me a valid file descriptor. Instead it returns -1. If I run the code again however, I get fid = 3.
This is being run on ubuntu but it apparently works fine on window开发者_如何转开发s and I can't figure out why.
-Mike
not sure if this helps, but note that if the folder doesn't exist, fopen with 'w' can't create the file and so returns -1.
You should check out the two-output-argument form of fopen
in the doc here. This allows you to do stuff like
[fh, failmessage] = fopen( fname, 'wt' );
if fh == -1
error( 'Failed to open %s: %s', fname, failmessage );
end
精彩评论