[英]How to save array of structres in .mat file in matlab
如何在Matlab的.mat
文件中保存结构数组? 可能吗?
p(1).x=0;
p(1).y=0;
p(2).x=1;
p(2).y=1;
save('matfilename','-struct','p');
% ??? Error using ==> save
% The argument to -STRUCT must be the name of a scalar structure variable.
您可以不带-struct
参数使用save
:
>> p(1).x = 0;
>> p(1).y = 0;
>> p(2).x = 1;
>> p(2).y = 1;
>> save('myvars.mat', 'p');
>> clear p;
>> load('myvars.mat');
>> p(1)
ans =
x: 0
y: 0
>> p(2)
ans =
x: 1
y: 1
如果要将x
和y
存储为单独的数组(如果p
是标量结构,则与-store
一样),则需要自己进行操作(可以使用fieldnames
函数来收集结构中所有字段的名称) )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.