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

倖福魔咒の 提交于 2019-12-30 17:48:00

问题


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't work and comes out with the message:

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

What am I doing wrong?


回答1:


The x has to be 'x':

 save(int2str(i), 'x');



回答2:


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')


来源:https://stackoverflow.com/questions/10574355/matlab-saveint2stri-x-doesnt-work-argument-must-contain-a-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!