【发布时间】:2014-05-08 06:48:31
【问题描述】:
我有一个名为 C875.004-03.B401.mat 的 matfile,其中包含结构 C1。 C1 是一个包含 100 个变量的 1X1 结构。我想删除结构并保存 matfile,这样当我在 matlab 中加载它时它只是一个包含 100 个变量的数组。有什么想法吗?感谢您的帮助!
【问题讨论】:
标签: arrays matlab save structure
我有一个名为 C875.004-03.B401.mat 的 matfile,其中包含结构 C1。 C1 是一个包含 100 个变量的 1X1 结构。我想删除结构并保存 matfile,这样当我在 matlab 中加载它时它只是一个包含 100 个变量的数组。有什么想法吗?感谢您的帮助!
【问题讨论】:
标签: arrays matlab save structure
或者只是使用 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 Help 上也有例子,这里引用了 -
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 类,它有助于将数据加载和保存到 mat 文件。以下是您的案例的示例。我假设所有变量都作为数组存储在名为str 的单个结构字段中。如果不是这样,请纠正我。
matObj = matfile('/path/to/C875.004-03.B401.mat');
matObj.C1=matObj.C1.str;
现在,C1 应该是一个数组。
【讨论】: