使用“保存”保存在目录中时出错

我想将工作空间保存在另一个目录中,并为此在Matlab中编写了以下内容:

fileName = [datestr(now,'dd-mmm-yyyy_HHMMSS') '_test'];
save('C:\Users\User\project',fileName)

它给了我错误:Error using save: '05-Nov-2019_083736_test' is not a valid variable name.

但是,如果我不给出目录地址就可以正常运行。

为什么会发生?

etreg 回答:使用“保存”保存在目录中时出错

您可以使用评论中的il_raffa的建议(稍作修正):

save(['C:\Users\User\project\' fileName])
%                           ^ add a folder separator here

或使用fullfile函数,以避免由于忘记文件夹分隔符而导致错误:

save(fullfile('C:\Users\User\project',fileName));

这也适用于子文件夹和文件名,例如

save(fullfile('C:\Users\User\project','matfiles',fileName));
本文链接:https://www.f2er.com/3161483.html

大家都在问