Matlab - save(int2str(i), x) doesn't work - Argument must contain a string

后端 未结 2 1174
孤独总比滥情好
孤独总比滥情好 2021-01-17 21:47

I have a loop which is generating some data and in certain cases I want to save the data. Therefore I have:

save(int2str(i), x);

This doesn

相关标签:
2条回答
  • 2021-01-17 22:19

    Both the filename (in your case you correctly convert what I'm guessing is the loop index, i to a string) and the names of the variables that you want to save must be strings. You can save multiple variables to the same mat file by separating the variable names by commas. The Matlab documentation gives the following example . . .

    savefile = 'pqfile.mat';
    p = rand(1, 10);
    q = ones(10);
    save(savefile, 'p', 'q')
    
    0 讨论(0)
  • 2021-01-17 22:35

    The x has to be 'x':

     save(int2str(i), 'x');
    
    0 讨论(0)
提交回复
热议问题