1
%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

How do I write some Matlab script that will read in one .mat file after another...

tshepang
  • 12,111
  • 21
  • 91
  • 136
2one
  • 1,035
  • 3
  • 17
  • 36

2 Answers2

2

You file names are stored in n, so you should be able to do:

for l=1:length(oar)
    load(n{l})
end
am304
  • 13,758
  • 2
  • 22
  • 40
1

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.

Pursuit
  • 12,285
  • 1
  • 25
  • 41