Help fixing fopen error in code
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Kristine
il 27 Mag 2025
Risposto: Walter Roberson
il 28 Mag 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 Commenti
Risposta accettata
Walter Roberson
il 28 Mag 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Get Started with MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!