Help fixing fopen error in code
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kristine
el 27 de Mayo de 2025
Respondida: Walter Roberson
el 28 de Mayo de 2025
MATLAB is not letting me create breaks between text…
Hi y’all,
I am trying to sun the following code:
files=dir('txt*.txt'); %additional filter so i didn't read in my merged file
fileout='merged.txt';
fout=fopen(fileout,'w');
for cntfiles=1:length(files)
fin=fopen(files(cntfiles).name);
temp = fread(fin,'uint8');
fwrite(fout,temp,'uint8');
fprintf(fout,'\n');
fclose(fin);
end
fclose(fout);
When I run it, I get an error:
Error using fread.
Invalid file identifier. Use fopen to generate a valid file identifier.
But I am using fopen. I don’t know how to resolve this issue.
0 comentarios
Respuesta aceptada
Walter Roberson
el 28 de Mayo de 2025
filename = fullfile(files(cntfiles).folder, files(cntfiles).name);
[fin, msg] = fopen( filename );
if fin < 0
error('failed to open "%s" because "%s"', filename, msg);
end
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!