Matlab的“保存”函数 - 如何将 .mat 文件内的变量命名为与文件名相同?
我想将每个 case_no
的 q
结果保存在 q_cases
相应字符串中作为 .mat 文件。根据我的 save(q_cases{case_no},'q')
语句,即使文件名作为 q_cases
的相应字符串出现,但是所有这些 .mat 文件包含与q
同名的变量。当我打开这些 .mat 文件时,我会得到所有 3 个文件的一个名为 q
的变量。但是,我希望存储在这些文件中的变量名称与文件名称相同,分别为 q_a
、q_b
和 q_c
。
I want to save the result of the q
for each case_no
in corresponding string of the q_cases
as a .mat file. With my statement of save(q_cases{case_no},'q')
even though the names of files are coming as the corresponding string of q_cases
, however all those .mat files contain variable with the same name of q
. When I open those .mat files I get a variable with name q
for all the 3 files. However, I want the names of the variables stored in those files same as the name of the files i.e. q_a
, q_b
and q_c
respectively.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决此问题的一种方法是使用 eval 分配变量名称。
编辑
通常不建议使用 Eval,因为它很难调试/维护。因此,您可以首先创建一个结构并使用
-struct-保存选项
,如下所示:
One way to solve this is to assign the variable name with eval.
EDIT
Eval is usually not recommended, since it is difficult to debug/maintain. Thus, you can instead create a structure first and use the
-struct
-option of save, like this: