- 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
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!