MATLAB: Increment file name by adding numbers in a loop

incrementloopsave

I want to select data piecewise in a loop, and I want to be able to save the files as filename_number, where the number increases for each iteration of the loop. Is there an easy way to accomplish this?
The idea is: first selection, saved file name is file_1 second selection, saved file name is file_2 etc

Best Answer

Easy way to increment your filename is:
filename = sprintf('%s_%d','filename',k)