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.

 채택된 답변

Honglei Chen
Honglei Chen 2017년 12월 13일

1 개 추천

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

i try to use only
Filename = fullfile(myFolder,baseFilename);
but it can't read the file.I need to use sprintf actually..to read all the values as a string (in each file).
baseFilename already includes the .txt part . Just
Filename = fullfile(myFolder,baseFilename);
should work
milly edros
milly edros 2017년 12월 14일
thank you very much to both of you..

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Filename Construction에 대해 자세히 알아보기

질문:

2017년 12월 13일

댓글:

2017년 12월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by