Filter löschen
Filter löschen

Get outputs of blocks of a given type in system target

2 Ansichten (letzte 30 Tage)
Olaf Oelsner
Olaf Oelsner am 12 Feb. 2019
Bearbeitet: Agnish Dutta am 25 Feb. 2019
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.

Antworten (1)

Agnish Dutta
Agnish Dutta am 25 Feb. 2019
Bearbeitet: Agnish Dutta am 25 Feb. 2019
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.

Kategorien

Mehr zu Simulink Coder finden Sie in Help Center und File Exchange

Produkte


Version

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by