Hello. I have 150 images (images_0, images_1, images_2, ……, images_140) which are saved in 4 folders called : dataset_1, dataset_2, dataset_3 and dataset_4.
I use this code to rename images
mainDirectory = 'C:\Users\Desktop\data';subDirectory = dir([mainDirectory '/dataset_*']);for m = 1 : length(subDirectory) subFolder = dir(fullfile(mainDirectory, subDirectory(m).name,'*.png')); fileNames = {subFolder.name}; for iFile = 1 : numel( subFolder ) newName = fullfile(mainDirectory, subDirectory(m).name, sprintf('%00d.png',(iFile) ) ); movefile( fullfile(mainDirectory, subDirectory(m).name, fileNames{ iFile }), newName ); endend
This code works well, but I'm new in MATLAB and I want to change the newName as follows : (number of the dataset)_(name of the image)
For example : 1_images_0, 1_images_1, 2_images_0, 2_images_1, …
Please, any idea how can I change the newName to rename the images? Please help me and thanks in advance.
Best Answer