Automatically Run Script at End of Toolbox Installation

6 visualizaciones (últimos 30 días)
Paul Wintz
Paul Wintz el 2 de Oct. de 2021
Respondida: Lars Lindner el 5 de Feb. de 2025 a las 10:11
I'm writing a toolbox and packaging it as described in Create and Share Toolboxes. At the end of the installation process, I want to automatically run a script. Is this possible? We are trying to support MATLAB R2016a onward.

Respuesta aceptada

Jan
Jan el 3 de Oct. de 2021
I include a function, which runs once the first time the toolbox is called instead. This is "after the installation", but not directly after the installation, but before the first run. I use ispref and setpref to set a flag, which is persistent between Matlab sessions. But it matters as which user you run the toolbox.
  2 comentarios
Paul Wintz
Paul Wintz el 5 de Oct. de 2021
How do you handle this when there are many functions and classes in the toolbox? Do you just run the setup code at the beginning of every function?
Jan
Jan el 6 de Oct. de 2021
If there are no "main functions", e.g. a GUI, this is not trivial. Adding a:
checkInstalled;
and
function checkInstalled
persistent runOnce
if isempty(runOnce)
runOnce = true;
callYourSetupRoutine;
end
end
takes about 0.5 seconds for 1e6 calls. But is this installation really required in all subfunctions?

Iniciar sesión para comentar.

Más respuestas (1)

Lars Lindner
Lars Lindner el 5 de Feb. de 2025 a las 10:11
Hello everybody, we have the same issue.
We build a custom library, which we want to distribute as a toolbox (.mltbx file). I want to simple run a custom Matlab script (.m file), when installing this toolbox with right-click -> Install.
What is the correct approach to this?
Thank you everybody and with best wishes,
Lars

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by