Hey guys. I have some difficulty in creating a filename. okay, here is what I want to do: a matlab function called file_save(filename,input_data) is to save data into a xml file. so in a for loop, I want to create xml file with sequential filename eg. output1.xml output2.xml output3.xml
I guess there are some way of combining filename? Can anybody give me some help?
Thanks!
You can concatenate strings the same way as arrays in MATLAB. (Actually, strings are treated like character arrays.)
For file #n,
should get you what you want.
As @Andrew points out in the comments, you can also use sprintf to format the filename:
where N is the total number of files you plan on naming, and n is your current iteration. The
ceil(log10(N+1))gets you the number of digits you need for correct leading zero-padding.@Azim points out that num2str can accomplish the same thing: