Force default datatype to single in undefined Simulink blocks

16 ビュー (過去 30 日間)
Radu
Radu 2025 年 2 月 12 日
コメント済み: Radu 2025 年 2 月 13 日
Hi,
I am working in Simulink and generate C code for an embedded target and I am facing an issue with the default data type. I put together a test model to describe my issue, I have the following:
1) Initialisation y = 1 in a Matlab Function
2) Stateflow with a signal set inside to value locParam = 1
3) Normal constant with Inherit from 'Constant value'
set_param('teest', 'DefaultUnderspecifiedDataType', 'double');
I then do set_param('teest', 'DefaultUnderspecifiedDataType', 'single'); instead of the default 'double' I get the same result apart from the ground block which changes to single.
If I set the Constant to inherit via back propagation then the data type changes to single.
Is there a way to change a master setting to whenever the compiler sees a value unpecified defaults it to single without manually type casting them (i.e. for the Matlab function y = single(1) and for Stateflow locParam = single(1). Both the Matlab function and Stateflow have Inherit: Same as Simulink datatypes in the Property Inspector).
Thanks!

採用された回答

Fangjun Jiang
Fangjun Jiang 2025 年 2 月 12 日
'DefaultUnderspecifiedDataType' is not the same as 'Default DataType'. Your setting only applies to the Constant block because its data type is 'Underspecified' since there is no info to 'back propagation'. It also applies to the Ground block because its data type is not specifed (it is built that way).
I've seen many questions or requests to be able to replace 'double' with 'single' in one setting. I am not aware of such capability. It might be too risky to allow to do that because of the need for data accuracy.
If you really want all the data types in your model to be 'single'. You can put that in your model specifically. Once you specify the source data, the rest can be propagated so the actual work may not be too much.
If you are generating code, you might want to look into "Data Type Replacement". I wonder if it is pobbile to map both 'double' and 'single' data type to a single customized data type. Again, there are limitations and it might be risky.
  1 件のコメント
Radu
Radu 2025 年 2 月 13 日
Thanks for your help. yes I am aware I can specifically cast these to single. However, I am in a process of converting a very large model from double to single and it will be tedious.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEvent Functions についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by