필터 지우기
필터 지우기

Get outputs of blocks of a given type in system target

조회 수: 2 (최근 30일)
Olaf Oelsner
Olaf Oelsner 2019년 2월 12일
편집: Agnish Dutta 2019년 2월 25일
I am implementing a system target file and I want to access the outputs of blocks of a given type e.g., I want to get the outputs of all gain blocks in a model.
Suitable blocks in subsystems must also be found.
I need a solution which is independent from a particlar model. There are no assumptions about the name of the blocks or structure of the model.
What would be the best approach to achieve this?
Many thanks.

답변 (1개)

Agnish Dutta
Agnish Dutta 2019년 2월 25일
편집: Agnish Dutta 2019년 2월 25일
You can get the handles to all the blocks of a particular type using 'Simulink.findBlocksOfType('<model_name>', '<type_of_block>')'. Once you have them, obtain the port handles to each of the blocks using 'get_param(blockHandle, 'PortHandles')' and set the 'DataLogging' parameter to 'on' through 'set_param(portHandle.Outport(1), 'DataLogging', 'on')'.
Use the following script to do this:
targetBlocks = Simulink.findBlocksOfType('<name_of_model>', 'Gain');
for i = 1: size(targetBlocks, 1)
blockPH = get_param(targetBlocks(i), 'PortHandles');
set_param(blockPH.Outport(1),'DataLogging','on');
end
This needs to be done at the beginning of the simulation. So it is a good idea to include this as a part of the model callback fucntion, InitFcn. This can be accessed from: Model Configuration Parameters / Model Properties / Callbacks/ InitFcn.
After running the model, the output signal data will show up in the workspace as a 'Dataset' variable named 'logsout'. This variable will contain the output signals of all the required blocks.
Relevant links:
  1. https://www.mathworks.com/help/simulink/slref/simulink.findblocksoftype.html // To find a particular type of block.
  2. https://www.mathworks.com/help/simulink/slref/get_param.html //Obtain parameters of a block / subsystem given its handle.
  3. https://www.mathworks.com/help/simulink/ug/configuring-a-signal-for-signal-logging.html#bsw9vzy // Configure signal for logging.

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by