Extract variables from multiple .mat files

I have ~250 *.mat files in a year with ~25 variables in each file. I need to extract 1 variable from all of the files and create a new *.mat file to validate against other data.
What is the best way to solve this?

Answers (2)

My code in this answer could be used for your task too. Take a look to see if you have further questions. Basically, you need to go through a for-loop looping on your ~250 .mat files, taking one variable at a time.

4 Comments

I'm still trying to figure this out. The *.mat files are not in sequential order. I used a for loop to open the files, no problem, but now I am trying to extract data from 3 variables (Lat, Lon and x). Each of these variables has the same matrix size. Lat is in one variable, Lon in another and I need to match those coordinates up to extract the variable x for all 226 files. My result should be 1 variable with a matrix size 226X3. The problem is, the Lat and Long are not listed in the same row, column in each variable.
This has to be possible!
Angela
You'll have to know how to get the variable assuming you are doing it manually one by one (by selecting a particular row and column) first and then write a program to do it automatically. Provide some representative data so it's easy to test it out.
Lat_coord(222,46);
Lon_coord(364,113);
x_value - let's call it 275 for example - is determined from Lat Lon, but the cell in variable "x_value" is unknown.
Matrix is 407X308, assume all other values NaN.
So how do you pick the value then?

Sign in to comment.

Asked:

on 15 Sep 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!