How to create my own model callback function (InitFcn, StartFcn,...) in Model properties/Callbacks panel ?
Show older comments
On the one hand, I ran a model A where paramaters were loaded (just before simulation) by a scirpt 'A_param.m' called by 'InitFcn' model callback. And everything works fine.
On the other hand, when one model is referenced by another one, I have a compilation error. For example, if we suppose that model A references model B. I noticed that 'InitFcn' callback from model B is executed before 'InitFcn' callback from model A, and parameters are still loaded by a scirpt called by 'InitFcn' model A callback. Then, Model B compilation fails because parameters are not yet loaded when compilation starts.
I cannot move scirpt A_param.m to 'InitFcn' callback from model A to model B because A_param.m has to belong to model A.
I cannot either move scirpt A_param.m to 'PreLoadFcn' or 'PostLoadFcn' callbacks because I want load parameters just before simulation.
I look for a solution as for example build my own model callback, for instance, 'PreInitFcn' which would be called before both 'InitFcn' callbacks to load parameters. Is it possible ?
Does anyone know an alternative solution to load parameters just before simulation but also before model B 'InitFcn' callback ?
Thanks in advance.
Answers (1)
Kaustubha Govind
on 17 Jul 2012
0 votes
Sorry, it is currently not possible to introduce your own model callback. The PostLoadFcn is the latest option that you have before InitFcn is called. Would it be possible for you to separate B's parameters from A's, and put them in B's InitFcn callback instead? That seems like the scalable thing to do.
2 Comments
Valery Carpentier
on 17 Jul 2012
Kaustubha Govind
on 18 Jul 2012
Valery: Please submit an enhancement request via Tech Support with your use-case for a "PreInitFcn" if you'd like the development team to be aware of this.
Categories
Find more on Model, Block, and Port Callbacks in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!