Azzera filtri
Azzera filtri

Get outputs of blocks of a given type in system target

2 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Agnish Dutta
Agnish Dutta il 25 Feb 2019
Modificato: Agnish Dutta il 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.

Categorie

Scopri di più su Deployment, Integration, and Supported Hardware in Help Center e File Exchange

Prodotti


Release

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by