更新:
这是一个众所周知的问题
bug
-链接需要登录到Mathworks才能访问它。
错误报告摘要
一个MATLAB用户自定义程序的实例
使用保存到MAT文件的类
可能无法加载版本7.6(R2008a)
如果其中一个属性值
是另一个MATLAB的实例
班
简单地说,Mathworks报告以前保存的顶级自定义对象可能加载不正确(如下所述),并且错误发生在保存步骤上。因此,MAT文件中的数据已损坏。
根据我的经验,这似乎是断断续续的。在一个数据分析应用程序中,我写出了75个MAT文件中的37个文件,这些文件保存时有以下损坏:(
小心使用用户定义的对象。我添加了下面的save测试,以确保数据没有损坏
save('MAT_file_name.mat');
tmp=load('MAT_file_name.mat');
if ~isa(tmp.bb,'superClass')
msgbox({'THE FILE WAS NOT SAVED PROPERLY', ...
' ', ...
[' MAT_file_name.mat',]})
end
这里我使用的是Matlab2008a。MATLAB-2009a修复了这个微妙的错误。
无论如何,按照我的两个类的定义方式,保存/加载循环会导致一个类(超类)的变量作为第二个类(propClass)的变量加载。
示例MATLAB(r2008a)会话
>> bb=superClass;
>> whos
Name Size Bytes Class Attributes
bb 1x1 60 superClass
>> save
>> clear
>> clear classes
>> load
>> whos
Name Size Bytes Class Attributes
bb 1x1 60 propClass
bb
从超类神秘地变成了propClass
类:超类
这个类需要包含一个propClass类型的数组,下面是它的简单定义
classdef superClass<handle
properties(SetAccess=private)
a = propClass.empty % need to set this property as type propClass
% otherwise the addProp method throws an error
count=0;
end
methods
function self=superClass
%empty class definitionS
end
function addProp(self)
p = propClass;
self.count = self.count+1;
self.a(self.count)=p;
end
end
end
类别:propClass
PropClass是超级类使用的第二个类。它的定义对于这个bug并不重要。
问题
那么,为什么在MATLAB-R2008a中进行加载操作后,超类被更改为propClass呢?第二,我如何更改
为了避免这种症状?
笔记
所以,如果我在保存之前调用superClass.addProp,那么
超类
到
propClass
没有发生。