How to get the port types and dimensions for a block

Technical Source
1 min readSep 17, 2021

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

ANSWER

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

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     2lcInputDataTypes =       'single'lcInputDimensions =       1     1lcInputDataTypes =       'int8'

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.