Chart中数据类型的运算规则
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
我在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后的数据类型为什么?
0 comentarios
Respuestas (1)
Zuber
el 9 de Mayo de 2023
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 comentarios
Zuber
el 11 de Mayo de 2023
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.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!