【问题标题】:Save a workspace with current time. MAtlab使用当前时间保存工作区。 MATLAB
【发布时间】:2019-10-26 07:51:58
【问题描述】:

我想用当前时间保存所有模拟变量和无花果。

我的解决方案:

t = datetime('now','Format','dd-MM-yyyy''_T''HHmmss');
t2 = datevec(t);
DateString = datestr(t2);
filename=[DateString,' all_variables_main '];
save(filename )
savefig(filename)

Matlab 报错如下:

Unable to write file 26-Oct-2019 09:47:15 all_variables_main : Invalid argument.

我做错了什么?

【问题讨论】:

    标签: matlab save save-as


    【解决方案1】:

    mat 文件名中不能有空格或冒号。您可以使用以下命令直接获取文件名中允许的格式的日期和时间:

    >> fileName = [datestr(now, 'dd-mmm-yyyy_HHMMSS') '_all_variables_main']
    fileName =
        '26-Oct-2019_103123_all_variables_main'
    >> save(fileName)
    

    【讨论】:

      【解决方案2】:

      包含: 字符的文件名不是有效的文件名。

      您可以将 : 替换为 "꞉" 字符。
      见:How to get a file in Windows with a colon in the filename?

      您可以将所有: 替换为 字符(unicode 字符A789,看起来像冒号),该字符可以在文件名中使用。

      filename(filename == ':') = char(hex2dec('A789'));
      

      确保在加载文件时使用正确的字符。

      备注:以上方案在Windows 10和MATLAB R2016a中测试过。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多