Is there a classdef startup/initializer method?

4 次查看(过去 30 天)
When a classdef is first loaded into memory (via object instance creation or static method call etc.), is there a way to get a startup/initializer method to automatically be called once? E.g., to do preliminary calculations needed to support the classdef functionality?

采纳的回答

Matt J
Matt J 2023-9-20
编辑:Matt J 2023-9-20
As one example, you can initialize a property with a class-related function like below. Various other options are discussed here and here.
classdef myclass
properties (Constant)
startupData=init()
end
end
function data=init() %class-related function
%Do initial stuff here.
end
  1 个评论
James Tursa
James Tursa 2023-9-20
编辑:James Tursa 2023-9-20
I think this will work for me. Thanks!
(Although in my application, init( ) is a myclass static method so it must be called myclass.init)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by