How Can I Automatically Load .mat Files in MATLAB?

  • Topic: MATLAB 
  • Thread starter mathia
  • Start date
  • Tags Tags
    files Matlab
3 replies · 3K views · last reply
mathia
Messages
15
Reaction score
0
Hi,

I have some *.mat files and I need to read them automatically, they are like:
PT2020-RSK1.778-ZONE49.8962.mat
PT2020-RSK2.776-ZONE47.5451.mat
PT2020-RSK3.776-ZONE46.041.mat
PT2020-RSK4.7695-ZONE56.5417.mat
PT2020-RSK5.7667-ZONE48.1113.mat

Are there any ways to load them into MATLAB automatically?

Thanks for your time.

Regards,
Mathias
 
You can use the load command. If you want them loaded from a script try something like
Code:
load PT2020-RSK1.778-ZONE49.8962.mat;
if you want them to always be in your workspace you can put the load command in your startup.m.
 
Thanks, But I want to load them automatically, I don't want to type the name of each individual mat file because I have 100000 mat files.
 
Put them in all in one directory then and play with the "what" command. So you'd do something like:

K = what(directory)

And now K will be a structure with the filenames, then you can just go through each K.mat with a for loop

for example:

for i = 1:length(K.mat)

load(K.mat{i})

(do stuff with it)

end