MATLAB: How to use xlswrite in a for loop without overwriting

export excel dataMATLAB

I'm trying to generate 31 excel files with a for loop:
days=31;
for i = 1:1:days
dataday = frequency(1,((i-1)*(size(frequency,2)/days)+1):(size(frequency,2)/days)*i);
xlswrite('frequency.xlsx',dataday');
end
Why I can not obtain 31 Excel files? Thanks in Advance!

Best Answer

If you wish to create a new Excel file for every iteration of the loop, you can use:
xlswrite(strcat('frequency',num2str(i)),dataday');
The term 'frequency' is concatenated with the iteration number.
The data for every iteration will be written to the first sheet of every file. The files will be saved in the current directory and will be named:
'frequency1.xls','frequency2.xls' ... 'frequency31.xls'