Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
can setProperties work with save and load?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (0개)
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!