Chart中数据类型的运算规则

2 次查看(过去 30 天)
萍
2023-5-3
评论: 2023-5-17
我在StateFlow的chart有限状态机中,写下如下命令:
Rail_numRev=uint32(Rail_numRev+1*Epm_nEng10ms);
其中,Rail_numRev定义为uint32,Epm_nEng10ms定义为fidxt(1,16,2^-1,0)数据类型,请问Rail_numRev+1*Epm_nEng10ms后的数据类型为什么?

回答(1 个)

Zuber
Zuber 2023-5-9
Hi,
I understand that you want to know the datatype of ‘Rail_numRev+1*Epm_nEng10ms’ in the following equation:-
Rail_numRev=uint32(Rail_numRev+1*Epm_nEng10ms);
Since ‘Rail_numRev’ is defined as uint32, it is an unsigned 32-bit integer. The data type of ‘Epm_nEng10ms’ is defined using the ‘fidxt’ function. Although the ‘fidxt’ function is not explicitly defined in the code you have shared, but seeing its definition it appears that it returns a fixed-point data type with word length of 16 bit. Assuming that ‘fidxt’ returns a fixed-point data type, then ‘Epm_nEng10ms’ would also be a 16-bit word length fixed-point data type.
When ‘Rail_numRev’ (an unsigned integer) is added to ‘1*Epm_nEng10ms’ (a fixed-point data type) the result should be a fixed-point data type. This can be verified by using ‘class’ function as follows:-
class(Rail_numRev+1*Epm_nEng10ms);
For more information on identifying the data type of a variable, please refer to the following documentation link:-
I hope it resolves your query.
  4 个评论
Zuber
Zuber 2023-5-11
In my answer, I assumed that fidxt() is an user-defined function since there is no such function in documentation. However, if it is a typo and you are using fixdt() function, it will return a Simulink.NumericType object.
In such a case, MATLAB will throw error on adding 'Rail_numRev' with '1*Epm_nEng10ms' since mathematical operations are not supported for operands of type 'Simulink.NumericType'. Please inform about your MATLAB version and system information, and if possible, upload a screenshot of how you are arriving on the result.
萍
2023-5-17
模型和数据字典见附件

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 复杂逻辑 的更多信息

标签

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!