Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

can setProperties work with save and load?

1 visualización (últimos 30 días)
Edward B
Edward B el 17 de Dic. de 2019
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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

Respuestas (0)

La pregunta está cerrada.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by