Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Loading mat files in Matlab

Tags:
  1. Feb 11, 2014 #1
    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
     
  2. jcsd
  3. Feb 11, 2014 #2

    jhae2.718

    User Avatar
    Gold Member

    You can use the load command. If you want them loaded from a script try something like
    Code (Text):

    load [COLOR="DarkOrchid"]PT2020-RSK1.778-ZONE49.8962.mat[/COLOR];
     
    if you want them to always be in your workspace you can put the load command in your startup.m.
     
  4. Feb 12, 2014 #3
    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.
     
  5. Feb 12, 2014 #4

    Pythagorean

    User Avatar
    Gold Member

    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook