How to get the "data outport/Inport" already existing Blocknames from my simulink model via mscript

4 次查看(过去 30 天)
Blocks = find_system(bdroot,'LookUnderMasks','all','BlockType','Data Outport');
I tried this code but it is not working to get the data Outport/Inport Blocknames

回答(1 个)

Sameer
Sameer 2024-3-28
编辑:Sameer 2024-3-28
Hi Vignesh
From my understanding, you are attempting to retrieve the names of specific blocks within your Simulink model using MATLAB scripting. Specifically, you are interested in identifying blocks that serve as data inputs and outputs, which you've referred to as "data outport/inport" blocks. However, the code snippet you've provided seems not to be working as expected.
The MATLAB command you've used with find_system is almost correct but seems to have a minor issue with the 'BlockType' value for finding Data Store Read/Write or Inport/Outport blocks in a Simulink model. The 'BlockType' for Inport and Outport blocks should be 'Inport' and 'Outport', respectively, not 'Data Inport' or 'Data Outport'. If you're looking to find Data Store Read and Data Store Write blocks, their 'BlockType' values would be 'DataStoreRead' and 'DataStoreWrite', respectively.
Here's how you can correctly use find_system to get the names of ‘Inport’ and ‘Outport’ blocks from your Simulink model:
% For Outport blocks
OutportBlocks = find_system(bdroot, 'LookUnderMasks', 'all', 'BlockType', 'Outport');
% For Inport blocks
InportBlocks = find_system(bdroot, 'LookUnderMasks', 'all', 'BlockType', 'Inport');
If you are looking for Data Store Read/Write blocks, use:
% For Data Store Read blocks
DataStoreReadBlocks = find_system(bdroot, 'LookUnderMasks', 'all', 'BlockType', 'DataStoreRead');
% For Data Store Write blocks
DataStoreWriteBlocks = find_system(bdroot, 'LookUnderMasks', 'all', 'BlockType', 'DataStoreWrite');
Make sure you run these commands while your Simulink model is open. The bdroot function returns the name of the currently open Simulink model, which is used as the starting point for find_system to search for blocks. If you have multiple Simulink models open, ensure that the one you are interested in is the active window or specify the model name directly instead of using bdroot.
For example, if your model name is 'myModel', you can specify it directly:
OutportBlocks = find_system('myModel', 'LookUnderMasks', 'all', 'BlockType', 'Outport');
This will return a cell array of strings, where each string is the path to an ‘Outport’ block within your model. You can similarly replace 'Outport' with 'Inport', 'DataStoreRead', or 'DataStoreWrite' to find those specific types of blocks.
I hope this helps!
Sameer

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by