Clear Filters
Clear Filters

How do I get the "Base Data Types" of the block Input/Output interface?

13 views (last 30 days)
I want to get the "Base Data Types" of the Simulink module, what should I do?
  1 Comment
Fangping
Fangping on 15 Jul 2024 at 7:48
function [lgc,in1data,in2data] = compadata(inportdata_1,inportdata_2)
if iscell(inportdata_1)
inportdata_1=inp
ortdata_1{:};
end
if iscell(inportdata_2)
inportdata_2=inportdata_2{:};
end
%%输入口1
in1obj = evalin('base',['whos(''',inportdata_1,''');']);
if ~isempty(in1obj)
switch in1obj.class
case 'Simulink.AliasType'
in1data = evalin("base",[inportdata_1,'.BaseType;']);
case 'Simulink.NumericType'
temstr = evalin("base",[inportdata_1,';']);
switch temstr.DataTypeMode
case 'Fixed-point: slope and bias scaling'
in1data='';
if strcmp(temstr.Signedness,'Signed')
in1data = 'sfix';
elseif strcmp(temstr.Signedness,'Unsigned')
in1data = 'ufix';
end
if temstr.Slope == 1
if contains(in1data,'sfix')
in1data=['int',num2str(temstr.WordLength)];
elseif contains(in1data,'ufix')
in1data=['uint',num2str(temstr.WordLength)];
end
else
if rem(log2(temstr.Slope),1) == 0
in1data = [in1data,num2str(temstr.WordLength),'_En',num2str(abs(round(log2(temstr.Slope))))];
else
in1data = [in1data,num2str(temstr.WordLength),'_Sp',strrep(num2str(temstr.Slope),'0.','')];
end
if temstr.Bias ~=0
in1data = [in1data,'_B',num2str(temstr.Bias)];
end
end
case 'Fixed-point: unspecified scaling'
in1data='';
if strcmp(temstr.Signedness,'Signed')
in1data = 'sfix';
in1data = [in1data,num2str(temstr.WordLength),'_En',num2str(temstr.WordLength-2)];
elseif strcmp(temstr.Signedness,'Unsigned')
in1data = 'ufix';
in1data = [in1data,num2str(temstr.WordLength),'_En',num2str(temstr.WordLength-1)];
end
case 'Fixed-point: binary point scaling'
in1data='';
if strcmp(temstr.Signedness,'Signed')
in1data = 'sfix';
elseif strcmp(temstr.Signedness,'Unsigned')
in1data = 'ufix';
end
if temstr.FractionLength ~= 0
in1data = [in1data,num2str(temstr.WordLength),'_En',num2str(temstr.FractionLength)];
else
if contains(in1data,'sfix')
in1data=['int',num2str(temstr.WordLength)];
elseif contains(in1data,'ufix')
in1data=['uint',num2str(temstr.WordLength)];
end
end
end
end
else
if ~isempty(Simulink.findIntEnumType(inportdata_1))
in1data = Simulink.data.getEnumTypeInfo(inportdata_1,'StorageType');
else
in1data = inportdata_1;
end
end
This is an example I wrote, later you can use for reference.

Sign in to comment.

Answers (2)

Piyush Kumar
Piyush Kumar on 20 Jun 2024
You can follow these steps -
  • Open your model in Simulink
  • DEBUG => Information Overlays => PORTS => Base Data Types
For the entire model, data types of each signal in the model.
  1 Comment
Fangping
Fangping on 26 Jun 2024 at 7:21
Thank you for your answer, but this I know to show. I want to get its underlying data type, which can be done by way of code. It can be obtained directly in code.
As shown in the figure above, I can only get the data type at position 1 by compiling, but the base type I actually use is sfix16_En6. So that's position 2. How to get this port directly using sfix16_En6.

Sign in to comment.


Amith
Amith on 20 Jun 2024
To determine the data types of Simulink modules, you can make use of the 'CompiledPortDataType' property.
Consider the below example which uses the Van der Pol oscillator model (`vdp`) available in MATLAB:
% open the model
vdp
% compile the model
vdp([],[],[],'compile');
% get the port handles
h = get_param('vdp/Mu','CompiledPortDataType');
% get the output port data type of the Mu block
h.OutPort{1};
% terminate the compilation
vdp([],[],[],'term')
Note: Compiling the model is a prerequisite for querying the data types.
  1 Comment
Fangping
Fangping on 26 Jun 2024 at 7:23
This method still cannot get the basic data type, described as follows:
As shown in the figure above, I can only get the data type at position 1 by compiling, but the base type I actually use is sfix16_En6. So that's position 2. How to get this port directly using sfix16_En6.

Sign in to comment.

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Tags

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!