how can ı solve this error ? Error using fprintf Invalid file identifier. Use fopen to generate a valid file identifier.

15 visualizaciones (últimos 30 días)
clear all;clc;
y=[2 3 4 5;5 6 7 8]
fid=fopen('myfile.txt','wt');
fprintf(fid,'%d,%d\n',y);
fclose(fid);

Respuesta aceptada

Jan
Jan el 31 de Mayo de 2015
Check the success of fopen in every case, under all circumstances, ever, nerver omit this test:
filename = 'myfile.txt';
filepath = cd;
file = fullfile(filepath, filename);
fid = fopen(file, 'wt');
if fid==-1
error('Cannot open file for writing: %s', file);
end
I guess you do not have privileges to write to the current folder.
  4 comentarios
Stephen23
Stephen23 el 19 de Jun. de 2017
Editada: Stephen23 el 19 de Jun. de 2017
Even better is to get the very informative message returned by fopen:
[fid,msg] = fopen(file, 'wt');
assert(fid>=3,msg)

Iniciar sesión para comentar.

Más respuestas (2)

Caio Vaz Rimoli
Caio Vaz Rimoli el 4 de Sept. de 2018
Just brief comment: I also got this error because I ran out HD memory.

Aparna Komarla
Aparna Komarla el 2 de Oct. de 2018
Creating the directory you are storing the files/data in first might help!

Categorías

Más información sobre Troubleshooting in MATLAB Compiler SDK 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