How to list all the blocks in a model programmatically?

Is there a command to get all the blocks and their paths of a model in a list?

 Accepted Answer

To get a list of all the blocks in a model programmatically, you can use the following code:
load_system('model_name')
bl = getfullname(Simulink.findBlocks('model_name'))
For more information about "Simulink.findBlocks", please refer to the following documentation: https://www.mathworks.com/help/simulink/slref/simulink.findblocks.html
The above code also finds the following types of blocks:
  • Blocks under masks.
  • Blocks that are commented out.
  • Variants of blocks.
But it does not find blocks that are present inside a library-linked block. To find such blocks, you have to create a "findOptions" object and set the "FollowLinks" option to "true".
Please refer to the following documentation for more information: https://www.mathworks.com/help/simulink/slref/simulink.findoptions.html

More Answers (0)

Categories

Find more on Modeling in Help Center and File Exchange

Products

Release

R2018a

Community Treasure Hunt

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

Start Hunting!