Simulink: programmatically find all blocks of a certain kind

조회 수: 15 (최근 30일)
fraben
fraben 2022년 2월 18일
답변: Animesh Gupta 2022년 9월 1일
Hello,
I would like to programmatically monitor the usage of certain kinds of blocks, in order to be warned if they are being used.
What i imagine is being able to do something like this (using pseudocode):
num_unwanted_elements = 0;
for el in Simulink.model_elements:
if el.type == "Unwanted_element":
num_unwanted_elements++;
end
end
Can i do that? If so, how?

답변 (2개)

Mark McBroom
Mark McBroom 2022년 2월 24일

Animesh Gupta
Animesh Gupta 2022년 9월 1일
Hello,
It is my understanding that you want to programmatically find all blocks of a certain kind.
The blocks of a certain kind can be found using findBlocksOfType method of Simulink.
For example - if the model name is "myModel", and you want to find all blocks of type "constant", you can use this method as
Simulink.findBlocksOfType("myModel", "constant");
It will return handles to all the blocks of "constant" type.
You can also refer the documentation in the following link - https://www.mathworks.com/help/simulink/slref/simulink.findblocksoftype.html
I hope it helps.

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by