. Advertisement .
. Advertisement .
Hi everyone, I’m learning about matlab. While working, I try undefined. As a result, I get the message:
Invalid file identifier. Use fopen to generate a valid file identifier.
What can I do about the “invalid file identifier. use fopen to generate a valid file identifier” issue? Is there a better approach?
fopenis fail because MATLAB is not permitted to read/write on the file you have specified. Therefore, the error appears.
This error will disappear if fopen is added permissions. You can see in http://www.mathworks.se/help/matlab/ref/fopen.html , the fopen syntax is:
‘r’ (default) | ‘w’ | ‘a’ | ‘r+’ | ‘w+’ | ‘a+’ | … are some possible permissions and and below is their functions:
‘r’ – Opening a file for reading.
‘w’ – Opening or creating a new file for writing. Cutting the existing contents, if have.
‘a’ – Opening or creating a new file for writing. Adding data to the end of the file.
‘r+’ – Opening file for reading and writing.
‘w+’ – Opening or creating new file for reading and writing. Cutting existing contents, if have.
‘a+’ – Opening or creating new file for reading and writing. Adding data to the end of the file.
If fopen is use with no permissions, or I use ‘r’ (default) option, fopen will return -1 value. It is an error. Then I use below commands and they give me success:
fid(file identification) is
fopen. It’s the output of
fopen. It is an integer that is not directly related to the file. To get
fid, you will need
fopen. You are probably using an incorrect
fid(file identification) in a file-related I/O command such as
fopenthat fails to succeed will give
-1. Any valid file that has been successfully
3or higher integer.
However, it is impossible to pinpoint the source of the error or bug without any code. You can use MATLAB to run the code one-by-one from
fopen(set breakpoint and then run your program), until
fid(or any other variable you use for file identifiers) changes between
fclose, or any data structure (if your code has more than one file identifier), it will be possible to see if that
fid(or any other variable name you used for file identifiers) is affected.