【问题标题】:How to load .mat file which has a variable filename?如何加载具有可变文件名的 .mat 文件?
【发布时间】:2013-07-17 15:59:55
【问题描述】:
%select all .mat files

oar = dir('*oar.mat'); n = {oar.name};

%loop through files

for l=1:length(oar);

load pat_oar(l) %<---this is the .mat file with variable filename


clear ...

end

如何编写一些 Matlab 脚本来读取一个接一个的 .mat 文件...

【问题讨论】:

    标签: matlab matlab-load


    【解决方案1】:

    使用函数形式。而不是:

    load pat_oar{I}
    

    使用

    load(pat_oar{I})
    

    使用 unix 风格的语法(即command arg1 arg2)调用 Matlab 命令只是command('arg1','arg2') 更冗长语法的语法简写。每当将参数存储在变量中时,使用更详细的语法是一个很常见的技巧。

    【讨论】:

      【解决方案2】:

      你的文件名存储在n,所以你应该可以这样做:

      for l=1:length(oar)
          load(n{l})
      end
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-12-17
        • 1970-01-01
        • 2012-05-28
        • 1970-01-01
        • 2018-03-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多