Force default datatype to single in undefined Simulink blocks

9 views (last 30 days)
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!

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 12 Feb 2025
'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 Comment
Radu
Radu on 13 Feb 2025
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.

Sign in to comment.

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!