poster
2019-12-10, 20:48
我想保存的结果q每个case_no在相应的字符串q_cases作为.MAT文件。使用我的save(q_cases{case_no},'q')语句,即使文件名作为相应的q_cases字符串q_cases ,但是所有这些.mat文件都包含具有相同名称q变量。当我打开这些.mat文件时,所有3个文件的名称都为q 。但是,我希望存储在这些文件中的变量名与文件名相同,即分别为q_a , q_b和q_c 。
回答:
解决此问题的一种方法是使用eval (http://www.mathworks.com/help/techdoc/ref/eval.html)分配变量名称。
编辑
通常不建议使用Eval,因为它很难调试/维护。因此,您可以先创建一个结构,然后使用save (http://www.mathworks.com/help/techdoc/ref/save.html)的-struct -option (http://www.mathworks.com/help/techdoc/ref/save.html) ,如下所示:
for case_no=1:length(n) [q,S]=q_from_A(nModel,nModel_want,nCell,T,A{case_no},B{case_no},C{case_no},D{case_no},E{case_no},F{case_no}); %# create structure for saving saveStruct = struct(q_cases{case_no},q,... S_cases{case_no},S); %# ... and save it save(q_cases{case_no},'-struct','saveStruct',q_cases{case_no}); save(S_cases{case_no},'-struct','saveStruct',S_cases{case_no}); end
更多&回答... (https://stackoverflow.com/questions/3869461)
回答:
解决此问题的一种方法是使用eval (http://www.mathworks.com/help/techdoc/ref/eval.html)分配变量名称。
编辑
通常不建议使用Eval,因为它很难调试/维护。因此,您可以先创建一个结构,然后使用save (http://www.mathworks.com/help/techdoc/ref/save.html)的-struct -option (http://www.mathworks.com/help/techdoc/ref/save.html) ,如下所示:
for case_no=1:length(n) [q,S]=q_from_A(nModel,nModel_want,nCell,T,A{case_no},B{case_no},C{case_no},D{case_no},E{case_no},F{case_no}); %# create structure for saving saveStruct = struct(q_cases{case_no},q,... S_cases{case_no},S); %# ... and save it save(q_cases{case_no},'-struct','saveStruct',q_cases{case_no}); save(S_cases{case_no},'-struct','saveStruct',S_cases{case_no}); end
更多&回答... (https://stackoverflow.com/questions/3869461)