How do I automatically run a MatLab Script when I start my simulation in simulink
Afficher commentaires plus anciens
I have a simulink model and it uses a bunch of variables. I also have a script that sets initial values for the variables. I currently run the script before I start my simulation by typing "run scriptname" at the MatLab prompt (or by righ clicking the script file and selecting "run"). I would like this script to automatically run when I start my simulations. I've read the documentation on callbacks in the model properties dialog. I have placed the callback under the StartFcn callback (I've tried just putting the script name, both with and without the .m suffix. )...It didn't run. I've tried it in the InitFcn callback. I've tried loading it in the PreLoadFcn callback. Nothing seems to cause it to run. Does anyone know how to use these callbacks or how I would run a .m file prior to starting my simulation (besides doing it by hand and typing it in at the MatLab prompt?
6 commentaires
Kaustubha Govind
le 28 Juin 2011
Is there an error or warning displayed about the callback not being able to run?
Jill
le 29 Juin 2011
Fangjun Jiang
le 29 Juin 2011
Try to put just the "scriptname" in the InitFcn callback.
Jill
le 29 Juin 2011
Hang yin
le 4 Sep 2015
just put the name without m in the InitFcn.
huneza khan
le 4 Mai 2023
hi ...though replying on a old post but just for info,,,error might be because of the fact that your current matlab working directory is not set to the path where you have saved your model and script file.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Model, Block, and Port Callbacks dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!