how to use sprintf with fullfile
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
milly edros
le 13 Déc 2017
Commenté : milly edros
le 14 Déc 2017
I have the following code:
myFolder = 'D:\data';
myFiles = fullfile(myFolder,'*.txt');
allFiles = dir(myFiles);
for i = 1 : length(allFiles)
baseFilename = allFiles(i).name;
Filename = fullfile(myFolder,baseFilename,sprintf('%d%02d.txt',i));
fid = fopen(Filename);
A{i} = fscanf(fid, '%d %d %d');
fclose(fid);
end
I got an error 'invalid file identifier'. My Filename is incorrect. How should i write sprintf together with fullfile. My file names written as 0101,0102,...,6001,6002.txt.
0 commentaires
Réponse acceptée
Honglei Chen
le 13 Déc 2017
Might be because
sprintf('%d%02d.txt',i)
You specified two formats but only one input. Maybe one of them is not needed?
HTH
3 commentaires
Walter Roberson
le 13 Déc 2017
baseFilename already includes the .txt part . Just
Filename = fullfile(myFolder,baseFilename);
should work
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Filename Construction dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!