I have a MATLAB script that I could have sworn worked fine the last time I used it (a year ago). Now, I get this error:
Invalid file identifier. Use fopen
I have used fopen
with permission and the same error came out. However, I started MATLAB as admin and that took care of the problem.
I encountered the same problem when trying to open ASF toolbox demos. Running Matlab as an administrator(right-click to open) seemed to solve this issue for me.
I solved this problem for my self by adding permission option to fopen. As you see in http://www.mathworks.se/help/matlab/ref/fopen.html , fopen syntax is:
fileID = fopen(filename,permission)
Possible permissions, for example are: 'r' (default) | 'w' | 'a' | 'r+' | 'w+' | 'a+' | ...
'r' – Open file for reading.
'w' – Open or create new file for writing. Discard existing contents, if any.
'a' – Open or create new file for writing. Append data to the end of the file.
'r+' – Open file for reading and writing.
'w+' – Open or create new file for reading and writing. Discard existing contents, if any.
'a+' – Open or create new file for reading and writing. Append data to the end of the file.
...
If I use fopen without permission option, or if I use 'r' (default) option, fopen will return -1, which is error. I success with this:
fid=fopen('tmp.txt', 'w');
fid=fopen('tmp.txt', 'a');
The path with a forward slash at the beginning can cause the same error.
filename = '/data/myfile.txt';
throws this error, while
filename = 'data/myfile.txt';
does not produce an error.
It also happens when trying to create a file in a non-existent directory. Try mkdir('folderName')
within MATLAB or just create the directory beforehand.
It also occurs when a script is trying to read beyond the end of the file.