Incrementing File names access
古いコメントを表示
Hi all, I am facing trouble with reading file names in Matlab. My file names are like 05170201.001, 05170201.002, 05170201.003, 05170201.004. For every iteration I need to read a new file followed by the previous one.Every time the new file name just changes in the last two digits. So, can anybody please explain me how to do this.These are text files and the file number is numerous and I am not able to figure out the logic. Can anybody suggest.
Also one more question. While I concatenate two string say '05' and '010301' I get '05010301'. Once I convert this to number using str2num I get 5010301. The first number 0 is missing and I don't want this to happen. Can anybody suggest.
Any Help is sincerely appreciated.
Regards,
Naveen BM
採用された回答
その他の回答 (1 件)
KL
2017 年 11 月 20 日
If your text files are in the same folder, then use dir,
folderInfo = dir('yourFolderName/*.txt');
This will return the filenames and some more properties of the text files. If you want to store the filenames alone in a cell array,
fileNames = {folderInfo.name};
Now that your file names are in this cell array, you can loop through it to do whatever you want,
for fno = 1:numel(fileNames)
currentFileName = fileNames{1};
%your operations
end
カテゴリ
ヘルプ センター および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!