Both file names (in your case, you correctly convert what I assume is the loop index, i to a string), and the names of the variables you want to keep should be strings. You can save multiple variables in the same mat file, separating the variable names with commas. The Matlab documentation provides the following example.,
savefile = 'pqfile.mat'; p = rand(1, 10); q = ones(10); save(savefile, 'p', 'q')
learnvst
source share