我有一个名为C875.004-03.B401的matfile。包含结构C1的mat。C1是包含100个变量的1X1结构。我想删除结构并保存matfile,这样当我在matlab中加载它时,它只是100个变量的数组。任何想法吗?谢谢你的帮助!
或者只使用save
和-struct
选项-
load('C875.004-03.B401.mat')
save('C875.004-03.B401.mat','-struct','C1')
它在我的MATLAB版本的文档中-
-struct'
Keyword to request saving the fields of a scalar structure as individual variables in the file. The structName input must appear immediately after the -struct keyword.
它在Mathworks帮助中也有示例,如这里引用的-
Create a structure, s1, that contains three fields, a, b, and c.
s1.a = 12.7;
s1.b = {'abc',[4 5; 6 7]};
s1.c = 'Hello!';
Save the fields of structure s1 as individual variables in a file called newstruct.mat.
save('newstruct.mat','-struct','s1');
Check the contents of the file using the whos function.
disp('Contents of newstruct.mat:')
whos('-file','newstruct.mat')
Contents of newstruct.mat:
Name Size Bytes Class Attributes
a 1x1 8 double
b 1x2 262 cell
c 1x6 12 char
您可以使用matfile
类,它可以帮助加载和保存数据到垫子文件。下面是您的案例的示例。我假设所有变量都存储在名为str
的单个结构字段中的数组中。如果不是这样,请纠正我。
matObj = matfile('/path/to/C875.004-03.B401.mat');
matObj.C1=matObj.C1.str;
现在,C1
应该是一个数组