Incrementing File names access
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (1)
KL
il 20 Nov 2017
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
1 Commento
Naveen Bandi
il 21 Nov 2017
Categorie
Scopri di più su Get Started with MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!