Matlab - save (int2str (i), x) does not work. The argument must contain a string

I have a loop that generates some data, and in some cases I want to save the data. That's why I am:

save(int2str(i), x); 

This does not work and comes out with a message:

 ??? Error using ==> save Argument must contain a string. 

What am I doing wrong?

+7
source share
2 answers

x should be "x":

  save(int2str(i), 'x'); 
+11
source

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') 
+1
source

All Articles