I've got a multidimensional .mat file with a bunch of m x n arrays where each one is called something different, for example f1
, f2
, etc. I want to open the .mat file up and analyze each file automatically. How do I do that?
Asked
Active
Viewed 132 times
2

gnovice
- 125,304
- 15
- 256
- 359

ahmet nurlu
- 21
- 1
1 Answers
5
If you know for certain that all the variables in the .mat file are M-by-N arrays to be processed, then this should work:
data = load('your_file.mat'); %# Load .mat file data into a structure
for name = fieldnames(data).' %'# Loop over the field names of the structure
mat = data.(name{1}); %# Get one structure field (i.e. matrix)
%# Process matrix here
end
The above uses the functions load
and fieldnames
, and accesses structure fields using dynamic field names.

gnovice
- 125,304
- 15
- 256
- 359
-
Holy crap, I didn't know about MATLAB's dynamic field references. +1 – Doresoom Jun 07 '10 at 15:17
-
2+1 also as a note, one can get the variable names inside a MAT-file using `who -file file.mat` – Amro Jun 07 '10 at 16:51