How to create my own model callback function (InitFcn, StartFcn,...) in Model properties/Callbacks panel ?

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)

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

Thank you. Unfortunately, I cannot split A_param.m into two files because B's parameters dependent on the context. If model B is referenced by an other model than A, parameters have to be different. It seems that I have to accept using PostLoadFcn even if parameters may change between loading and starting simulation... or pray that 'PreInitFcn' will be implemented in the next release.
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.

Sign in to comment.

Products

Asked:

on 17 Jul 2012

Community Treasure Hunt

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

Start Hunting!