matlab - How to batch rename files to 3-digit numbers? -


i apologize in advance question not specific. goal take bunch of image files, named as: 0.tif, 1.tif, 2.tif, etc... , rename them numbers 000.tif, 001.tif, 002.tif, ... , 010.tif, etc...

the reason want because trying load images matlab , batch processing matlab not order them correctly. use dir command dir(*.tif) images , load them array of files can iterate on , process, in array element 1 0.tif, element 2 1.tif, element 3 10.tif, element 4 100.tif, , on.

i want keep ordering of elements process them. however, not care if have change order of elements before processing them (i.e. can make work rename, example, 2.tif 10.tif if had to) looking way convert file names way described.

if there better way matlab order files when loads them array using dir please let me know because easier.

thanks!!

you can without having rename files, if want. when grab files using dir, you'll have list of files so:

files =     '0.tif'    '1.tif'    '10.tif'    ... 

you can grab numeric part using regexp:

nums = regexp(files,'\d+','match'); nums = str2double([nums{:}]); nums =    0 1 10 11 12 ... 

regexp returns matches cell-array, second line converts actual numbers.

we can actual numeric order sorting resulting array:

[~,order] = sort(nums); 

and put files in correct order:

files = files(order); 

this should (i haven't tested it, don't have folder full of numerically labelled files handy) produce list of files so:

files=    '0.tif'    '1.tif'    '2.tif'    '3.tif'    ... 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -