How to get the port types and dimensions for a block

K
Kevin · Sep 17, 2021 · 2.3K views
Question
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 PhD Expert
Answered Aug 25, 2026
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'

 

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!