how to use sprintf with fullfile
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Honglei Chen
2017-12-13
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 个评论
Walter Roberson
2017-12-13
baseFilename already includes the .txt part . Just
Filename = fullfile(myFolder,baseFilename);
should work
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Filename Construction 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!