Can classes be made unsaveable

조회 수: 3 (최근 30일)
Oliver Woodford
Oliver Woodford . 2014년 2월 14일
답변: Oliver Woodford . 2014년 2월 18일
Is there a way to define a class such that the MATLAB save() function throws an error when it tries to save an instance of that class? E.g.
>> h = myclass();
>> save h
Error: Instances of myclass cannot be saved.

채택된 답변

Oliver Woodford
Oliver Woodford 2014년 2월 18일
No. When a class object is saved, the saveobj method for that class gets called, if it exists. If this method throws an error, it is caught, and thrown as a warning instead. Therefore the best you can do is generate a warning. If you don't want the object to be saved, then you can have the saveobj method return an empty array, which is saved instead:
classdef myclass
function a = saveobj(obj)
a = [];
Warning 'myclass objects are unsaveable.'

추가 답변 (0개)


Help CenterFile Exchange에서 Object Save and Load에 대해 자세히 알아보기


Community Treasure Hunt

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

Start Hunting!

Translated by