What causes an invalid file identifier in MATLAB?

I have a MATLAB script that I could swear worked fine the last time I used it (a year ago). Now I get this error:

Invalid file identifier.  Use fopen to generate a valid file identifier.

If I understand correctly, it cannot find or open (?) The file specified elsewhere in the script. It is right? If so, what can cause this?

+5
source share
10 answers

fid ( ) - fopen. , . fopen, fid. , fid ( ) -, , fread, fscanf fclose. fopen fid of -1. fopen fid, 3 .

- , . MATLAB fopen ( ) fclose , fid ( ) ( ) fopen fclose.

+10

, fopen. http://www.mathworks.se/help/matlab/ref/fopen.html, fopen:

fileID = fopen(filename,permission)

, :  'r' ( ) | 'w' | 'a' | 'r +' | 'w +' | 'a +' |...

'r' - .

'w' - . , .

'a' - . .

'r +' - .

'w +' - . , .

'a +' - . .

...

fopen , "r" ( ), fopen -1, . :

fid=fopen('tmp.txt', 'w');
fid=fopen('tmp.txt', 'a');
+8

. , , , ( ). , , . !

, .

+6

ASF. Matlab ( ), , .

+6

fopen , MATLAB / .

, /MATLAB ( ).

+3

fopen . , MATLAB admin, .

+1

, excel, fopen -1. , ​​ .

0

.

filename = '/data/myfile.txt';

,

filename = 'data/myfile.txt';

.

0

This also happens when trying to create a file in a non-existent directory. Try it mkdir('folderName')in MATLAB or just create a directory in advance.

0
source

This also happens when a script tries to read outside the file.

-3
source

All Articles