How to get the port types and dimensions for a block

Illustration
Kevin - 2021-09-17T10:16:49+00:00
Question: How to get the port types and dimensions for a block

We are generating code using RTW via a script. I am trying to collect the port dimensions and data types. Argument names would be great too, but not required.   I am currently able to get the port names

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

Sometimes it is hard to find help in the document. Many times I just poke around and make an educated guess. I made a simple model and ran the code below. It seems to be able to get the dimension and data types. Hope this will help.
 
clc;
acModelName=bdroot;
lcInportHandles = find_system(acModelName,'FindAll','On','SearchDepth',1,'BlockType','Inport');
  for i=1:length(lcInportHandles)
    lcInputDimensions = get_param(lcInportHandles(i),'CompiledPortDimensions');
    lcInputDimensions=lcInputDimensions.Outport
    lcInputDataTypes = get_param(lcInportHandles(i),'CompiledPortDataTypes');
    lcInputDataTypes = lcInputDataTypes.Outport
end

The output looks like this:

lcInputDimensions =

       1     2

lcInputDataTypes = 

      'single'

lcInputDimensions =

       1     1

lcInputDataTypes = 

      'int8'

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!