Textscan error in code

3 visualizaciones (últimos 30 días)
Farzaneh ziaee
Farzaneh ziaee el 14 de En. de 2016
Respondida: Yuvasai Ayush el 31 de Mayo de 2023
Hello
I try to run a matlab code for my data analysis and in the first step I get this error:
Error using textscan
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in import_data (line 38)
dataArray = textscan(fileID, formatSpec, endRow(1)-startRow(1)+1, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines', startRow(1)-1, 'ReturnOnError',
false);
Error in Ions_Pimms (line 58)
[x,y,tof,bid] = import_data(fname);
I do not understand how should I resolve this problem. Can some one help me? Thanks.

Respuesta aceptada

Stephen23
Stephen23 el 14 de En. de 2016
Editada: Stephen23 el 14 de En. de 2016
Basically this means that fopen did not manage to open any file, and returned an error value instead of a valid file identifier. Usually this error occurs because no such file exists at the location with the name that the user passed to fopen. Alternatively that they have not passed any path information to fopen, which will then look only in the current directory.
The first step is to check the error code of fopen, and see what value it has. The fopen documentation explains that "If fopen cannot open the file, then fileID is -1.", so you should check this value. You might also like to check the second output, which is an error message:
[fileID,errmsg] = fopen(...);
And of course check the input to fopen, and confirm that it is the (path+)name of an existing file in that location.
  2 comentarios
Stephen23
Stephen23 el 14 de En. de 2016
Editada: Stephen23 el 14 de En. de 2016
Like many programming questions there is no "right" answer. Is the file in the current directory, or elsewhere? Are you using relative or absolute paths? How are you specifying the input to fopen? What is the input string to fopen when the error occurs?
You actually need to tell us some information about the situation, otherwise I have to rely on guessing or reading your mind.
Farzaneh ziaee
Farzaneh ziaee el 14 de En. de 2016
No it was not at that place. Thanks it was the issue I think :)

Iniciar sesión para comentar.

Más respuestas (1)

Yuvasai Ayush
Yuvasai Ayush el 31 de Mayo de 2023
The first step is to check the error code of fopen, and see what value it has. The fopen documentation explains that "If fopen cannot open the file, then fileID is -1.", so you should check this value. You might also like to check the second output, which is an error message:Basically this means that fopen did not manage to open any file, and returned an error value instead of a valid file identifier. Usually this error occurs because no such file exists at the location with the name that the user passed to fopen. Alternatively that they have not passed any path information to fopen, which will then look only in the current directory.
[fileID,errmsg] = fopen(...);

Categorías

Más información sobre Low-Level File I/O en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by