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

조회 수: 5 (최근 30일)
Fangping
Fangping 2024년 6월 20일
댓글: Fangping 2024년 7월 15일
I want to get the "Base Data Types" of the Simulink module, what should I do?
  댓글 수: 1
Fangping
Fangping 2024년 7월 15일
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.

댓글을 달려면 로그인하십시오.

답변 (2개)

Amith
Amith 2024년 6월 20일
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
Fangping
Fangping 2024년 6월 26일
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.

댓글을 달려면 로그인하십시오.


Piyush Kumar
Piyush Kumar 2024년 6월 20일
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
Fangping
Fangping 2024년 6월 26일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Arduino Hardware에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by