MATLAB: save a class property -
i'd save particular class property disk, while ignoring rest of class properties. think matlab allows saveobj method overridden purpose. however, saves class object property attached. want save property itself, without of class information.
i might think suitable method like:
classdef myclass properties myprop end methods def b = saveobj(a) b = a.myprop; end def save(a,fname) save(fname,'a.myprop'); end end end but neither of these have desired effect. can me, please?
you can overload save function without having go through saveobj:
classdef myclass properties myprop end methods function [] = save(a,fname,varargin) myprop = a.myprop; %#ok<prop,nasgu> save(fname,'myprop',varargin{:}); end end end then on command window:
>> foo = myclass(); >> foo.myprop = 4; >> foo.save('var.txt'); >> bar = load('var.txt','-mat'); >> bar.myprop ans = 4
Comments
Post a Comment