Incrementing File names access
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
KL
el 20 de Nov. de 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 comentario
Naveen Bandi
el 21 de Nov. de 2017
Categorías
Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!