Guy on Simulink

Simulink & Model-Based Design

Is that model already open?

I was just clicking through my vast inbox of unread e-mail, and saw a MATLAB Central news reader alert.

MATLAB Central News Reader alerts

I quickly scanned the message and then clicked on the link to view the thread on MATLAB Central.

Simulink open_system thread on the MATLAB Central News Reader

Regular contributor Ben Harper asked the question:

i can open a simulink file with "open_system" command. I want to see if the simulink model is opened?
how can i check whether the mdl file is opened or not?

thank you.

His first response came from Jason Retik:

openModels = find_system('SearchDepth', 0)

openModels will be a cell array of all the currently opened models. You can use the STRCMP function on openModels to check whether a particular model is open.

This has all the ingredients to get Ben up and running, but Gavin Walker also replied:

Try "bdIsLoaded"


While I thought a function like this existed, it wasn't at the top of my mind. bdIsLoaded returns true for models that are in memory. The function takes a model name as a string, or a cell array of model names as its input.

If you edit bdIsLoaded.m, you will see that it includes the exact find_system call Jason suggested, plus a little code to check if your specific model is loaded.

Is that the answer?

Going back to the original question, I want to further improve this answer. The original question was about the use of open_system, which is different than load_system. Block diagrams can be loaded, but not visible to the user. I think Ben's original question is whether a particular model is visible or not, so here is my answer:

First check to see if the model is loaded, and if it is, use get_param to check the Shown property. Here is an example: >> load_system('vdp')
>> bdIsLoaded('vdp')
ans =
>> get_param('vdp','Shown')
ans =
>> open_system('vdp')
>> get_param('vdp','Shown')
ans =

The model is only visible if Shown==on.

Where do you get your answers?

How about technical support? Leave a comment here and tell us about it.



To leave a comment, please click here to sign in to your MathWorks Account or create a new one.