Or you can simply create a new file on each iteration:
save(sprintf('name%04d.mat',k),'X')
Note: the-append option should really be named the-replace option, as thesave documentation makes clear:"save(filename,variables,'-append') adds new variables to an existing file. If a variable already exists in a MAT-file, then save overwrites it. The variables argument is optional."
Best Answer