See:
- FAQ: How to process a sequence of files (link)
- https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.html
BaseFolder = tmpdir;
for k = 1:100
...
FileName = fullfile(BaseFolder, sprintf('Image%04d.png'));
imwrite(Data, FileName);
end