当前位置: 动力学知识库 > 问答 > 编程问答 >

matlab - Get calling simulink object/model reference from called script

问题描述:

This is in regards to Matlab 2011b Simulink environment:

I need to run a script as a callback on a model. How can I obtain the reference to the calling model, from the script? I'm protecting for the calling model not being the "current" or the highlighted model necessarily. Not sure if highlighted and current are different concepts

网友答案:

There's no mechanism for a callback script (or function) to automatically determine which model it was called from.

If you can, then within the callback, but before calling your script, define a variable in the (base) workspace that contains the model name as a string. Or if your callback is a function the pass it the name of the model as a string.

If your really want/need to search for the model name then you could use find_system to get the names of all open models; then look at the SimulationStatus property of the models to see which one(s) are currently running. If there are multiple running then you need to determine something else to differentiate between them.

There may be other approaches depending on exactly which callback you are using.

分享给朋友:
您可能感兴趣的文章:
随机阅读: