- https://www.mathworks.com/help/simulink/slref/simulink.findblocksoftype.html // To find a particular type of block.
- https://www.mathworks.com/help/simulink/slref/get_param.html //Obtain parameters of a block / subsystem given its handle.
- https://www.mathworks.com/help/simulink/ug/configuring-a-signal-for-signal-logging.html#bsw9vzy // Configure signal for logging.
Get outputs of blocks of a given type in system target
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
Agnish Dutta
el 25 de Feb. de 2019
Editada: Agnish Dutta
el 25 de Feb. de 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:
0 comentarios
Ver también
Categorías
Más información sobre Simulink Coder en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!