When saving images, it is easier to manage them if they are sequentially numbered.
ex) 001.jpg, 002.jpg, 003.jpg,.........100.jpg
%Assume jpg files of an MRI with multiple images for x = 1:length(MR_fl) img = imread(fullfile(main_fd,MR_fl(x))); %make save file path %'%03i' is the code to create sequential number save_fl= strcat(num2str(x,'%03i'),'.jpg'); %make full path save_path = fullfile(save_fd,save_fl); %Saving img with optimal color map (Color map is []) imwrite(img,[],save_path) end
if you want to get 4 digits, just write '%04i'.