How do I access the port width, data types, and dimensions individually for the blocks in my Simulink model from the MATLAB command line?
9 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Edited: MathWorks Support Team
on 21 Jul 2021
I would like to access the port width, data types, and dimensions individually for the blocks in my Simulink model from the MATLAB command line. I would like this to work with my bus signals as well.
Accepted Answer
MathWorks Support Team
on 24 Jun 2021
Edited: MathWorks Support Team
on 21 Jul 2021
The key to finding the signal/port dimensions and types at the command line (i.e. via m-file) is to put your model into a "compiled" state before querying the dimensions/types. During the compile phase, signal/port dimensions and data types are propagated through the model. First get your model into a compiled state (similar to a Ctrl+D or "Update Model" in Simulink):
>> myModel([],[],[],'compile')
For more on this command, you can refer to our Documentation:
Once you have your model in a compiled state, you can query particular ports for their dimensions following a workflow similar to:
You can also access the port width and data type by using "get_param" with the following properties:
"CompiledPortDataType"
"CompiledPortWidth"
An example code snippet (similar to the above linked example) is below:
myModel([],[],[],'compile')
q=get_param(gcb,'PortHandles');
get_param(q.Inport,'CompiledPortDataType')
get_param(q.Inport,'CompiledPortWidth')
myModel([],[],[],'term')
As the code snippet shows, once you finish querying your desired ports, make sure to move your model out of the compiled state and into the terminated state as:
>> myModel([],[],[],'term')
0 Comments
More Answers (0)
See Also
Categories
Find more on Composite Interfaces in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!