How can I programmatically close Simulink windows, such as scope windows and block parameters dialogs?

I have a number of windows open in my Simulink model (such as scopes, block parameters, etc...). I would like to put something similar to CLOSE ALL in a MATLAB file which will close all of these. How can I accomplish this?

 Accepted Answer

At a high level, you can accomplish this using the 'find_system' and 'close_system' commands. The specifics of how you call these depends on what you would like to close, but your workflow will likely take the following form:
  1. Create a new MATLAB script so that you can easily call your 'close everything' routine.
  2. Within the script, use 'find_system' to get references to all Simulink blocks you would like to close. For example, to get all scope blocks, you can call it like this:
    blocksToClose = find_system(bdroot, 'BlockType', 'Scope')
    You may need to perform multiple 'find_system' calls to obtain handles to all of the blocks you would like to close.
  3. Once you have handles to all of the blocks you would like to close, you can call 'close_system' to close their dialog boxes:
    close_system(blocksToClose)
  4. Run the script every time you would like to execute this behavior.
Depending on how many types of blocks you would like to close, it may instead be easier to find all of the blocks you do not want to close, and then take the complement. For example, let's say that you would like to close all Simulink block windows besides any systems/subsystems you have open. In this example, it would be more direct to:
  1. Create a MATLAB script.
  2. Call the below code to find all blocks in your model:
    blocks = find_system(bdroot)
  3. Call the below code to find all subsystems in your model:
    subsystems = find_system(bdroot, 'BlockType', 'Subsystem')
  4. Remove all blocks in the result from 3 from the result from 2. Then, call 'close_system' on this result. E.g.,
    toClose = blocks(~ismember(blocks, subsystems))
    toClose[1] = [] % Remove parent model so that we do not close it too.
    close_system(toClose)
Thus, we can close everything except for our main system and subsystems. 
To learn more about these MATLAB functions, please see the below documentation pages:
  1. find_system
  2. close_system
Specifically, I would like to direct your attention to the 'LookUnderMasks' flag for 'find_system', which might be needed if you would like to close the windows of blocks that are hidden under masked subsystems.

More Answers (0)

Categories

Products

Release

R2024b

Community Treasure Hunt

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

Start Hunting!