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?
我有一个多维的。mat文件,其中有很多mxn数组,每个数组都有不同的名称,例如f1、f2等等。我想打开。mat文件并自动分析每个文件。我该怎么做呢?
1 个解决方案
#1
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:
如果您确定.mat文件中的所有变量都是要处理的m×n数组,那么这应该是可行的:
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.
上面使用函数load和fieldname,并使用动态字段名访问结构字段。
#1
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:
如果您确定.mat文件中的所有变量都是要处理的m×n数组,那么这应该是可行的:
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.
上面使用函数load和fieldname,并使用动态字段名访问结构字段。