From: Eric He on 4 Jun 2010 11:10 Hi, I am trying to build a class that inherits from another class, in which both classes have the ability to save objects. The superclass code is as follows: classdef exclass properties value end methods function obj=exclass(in) obj.value=in; end function [val,obj]=myfun(obj) [val,obj]=obj.doubler(); end function [val,obj]=doubler(obj) obj.value=obj.value*2; val=obj.value; fprintf('%d',val); end function S=saveobj(obj) S.Pointvalue=obj.value; end function obj=reload(obj,S) obj.value=S.Pointvalue; end end methods (Static=true) function obj=objload(S) obj=exclass; obj=reload(obj,S); end end end and the subclass code is as follows: classdef myclass < exclass properties val end methods function obj=myclass(value,val) obj=obj(a)exclass(value); obj.val=val; end function S=saveobj(obj) S=saveobj(a)exclass(obj); S.Pointval=obj.val; end function obj=reload(obj,S) obj=reload(a)exclass(obj,S); obj.val=S.Pointval; end end methods (Static=true) function obj=loadobj(S) obj=myclass; obj=reload(obj,S); end end end While I can save and load the superclass fine, when I try saving and loading the subclass, all of the parameters of the loaded object are empty sets. The error I get is: Error occurred while trying to load object of type myclass: Input argument "value" is undefined. I understand that "value" is undefined, but how do I make a constructor where "value" doesn't need to be defined? Or how do I get a "value" when the myclass constructor doesn't have any inputs? Thanks, Eric
|
Pages: 1 Prev: How do you force decimal output? Next: Extract data from cell using matrix of index points |