Is there a classdef startup/initializer method?

3 Ansichten (letzte 30 Tage)
James Tursa
James Tursa am 19 Sep. 2023
Bearbeitet: James Tursa am 20 Sep. 2023
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?

Akzeptierte Antwort

Matt J
Matt J am 20 Sep. 2023
Bearbeitet: Matt J am 20 Sep. 2023
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 Kommentar
James Tursa
James Tursa am 20 Sep. 2023
Bearbeitet: James Tursa am 20 Sep. 2023
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)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by