How to load .mat file which has a variable filename?

前端 未结 2 460
-上瘾入骨i
-上瘾入骨i 2021-01-24 19:33
%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          


        
2条回答
  •  隐瞒了意图╮
    2021-01-24 20:03

    Use the functional form. Instead of:

    load pat_oar{I}
    

    Use

    load(pat_oar{I})
    

    Calling a Matlab command using the unix-style syntax (i.e. command arg1 arg2) is just syntax shorthand for the more verbose syntax of command('arg1','arg2'). It's a pretty common trick to use the more verbose syntax anytime an argument is stored in a variable.

提交回复
热议问题