Rename images using counter
2 views (last 30 days)
I have a matlab script with a loop that includes a python script. This python script generates an image file with the name 'A.tiff' for every run of the loop. The problem is that the new image generated overwrites the previous one but I really want all the images generated everytime the loop executes. I think of renaming the image file after its generated by adding a counter to the file name e.g. A_1, A_2, A_3, etc. I can use the 'movefile = (OldFileName, NewFileName)' but what lines of code can I use to insert a counter into the NewFileName argument?
Thanks for your help in advance.
Geoff Hayes on 8 Feb 2015
Olu - you can use sprintf to create the new file name. Something like
% call the python script to generate the A.tiff file
% create the new file name
newFileName = sprintf('A_%d.tiff',k);
% move the file
Try the above and see what happens!