フィルターのクリア

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
...
methods
function a = saveobj(obj)
a = [];
Warning 'myclass objects are unsaveable.'
end
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConstruct and Work with Object Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by