"I don't understand the sprintf what does the %3.3d.jpg do"
It is confusing because that formatting string uses undocumented behavior of sprintf.
Do NOT learn from that format string! (except perhaps how NOT to write format strings).
A naive interpretation of that format string might be
'%3.3d.jpg'
3 field width (min three characters)
.3 precision (makes no sense with 'd' conversion type or an integer value)
d conversion type (signed integer)
.jpg literal string '.jpg'
So we would expect this to print a string with minimum characters, but obviously requesting three fractional digits from an integer is absolute nonsense, and so the string is actually parsed like this:
'%3.3d.jpg'
3 field width (min three characters)
.3 number of digits including leading zeros (not documented!)
d conversion type (signed integer)
.jpg literal string '.jpg'
You can see this undocumented behavior with a few simple examples, e.g. a fieldwidth of 5:
>> sprintf('X%5.3d.jpg',7)
ans =
X 007.jpg
The proper, documented way to generate a string with leading zeros is like this:
>> sprintf('X%03d.jpg',7)
ans =
X007.jpg