how to use sprintf with fullfile

12 Ansichten (letzte 30 Tage)
milly edros
milly edros am 13 Dez. 2017
Kommentiert: milly edros am 14 Dez. 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.

Akzeptierte Antwort

Honglei Chen
Honglei Chen am 13 Dez. 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 Kommentare
Walter Roberson
Walter Roberson am 13 Dez. 2017
baseFilename already includes the .txt part . Just
Filename = fullfile(myFolder,baseFilename);
should work
milly edros
milly edros am 14 Dez. 2017
thank you very much to both of you..

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Filename Construction finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by