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?

 采纳的回答

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

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Modeling 的更多信息

产品

版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by