Info
This question is closed. Reopen it to edit or answer.
can setProperties work with save and load?
2 views (last 30 days)
Show older comments
Any class that is derived from < matlab.System has a problem with required and optional arguments
To illustrate, if you save the class VarArgClass below and run the line above it, it generates the message when loaded.
Apparently, when loading such objects after a save, MATLAB for soem reason creates a temporary instance of the object. However, MATAB apparently neglects to supply the required arguments to the constructor. So without the "try...catch" workaround below, you get an error on load.
Can this be fixed? Or is there a better workaround?
clear; obj = VarArgClass(1, 'propOptional', 2); save; load;
classdef VarArgClass < matlab.System
properties
propRequired
propOptional
end
methods
function self = VarArgClass(propRequired, varargin)
setProperties(self, length(varargin), varargin{:});
try
self.propRequired = propRequired; % required prop not supplied on load
catch
disp('This should only appear in a load');
end
end
end
end
0 Comments
Answers (0)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!