Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

can setProperties work with save and load?

1 view (last 30 days)
Edward B
Edward B on 17 Dec 2019
Closed: MATLAB Answer Bot on 20 Aug 2021
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

Answers (0)

This question is closed.

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!