Usage : filename = genfilename(fname)
This simple code will generate a 'free' pathname based on your suggestion (fname), to make sure you can save your data to a file without overwriting to an existing one.
Simple options allow you to use a certain number of digits or start numbering at a defined number.
(i did not know that function so thanks)
You are right, but one advantage of my script is that you still get control on the name of the file. It's basically for saving multiple versions of the same file, you will have a different number each time to avoid overwriting on the previous one.
You could just use the built-in tempname function
Faster for large number of existing files.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.