This enhancement has been incorporated in Release 2012a (R2012a). For previous product releases, read below for any possible workarounds:
Not being able to set the DataType of a Simulink.Parameter to ‘double’ is a known limitation with Simulink 7.3 (R2009a).
You can set the DataType of a Simulink.Parameter directly, but if you set it to ‘double’, you get the warning message “Switching 'double' data type to 'auto' for parameter object”, and DataType remains ‘auto’:
>> p=Simulink.Parameter;
>> p.Value=5;
>> p.DataType='double';
Warning: Switching 'double' data type to 'auto' for parameter object
>> sllastwarning
ans =
Type: 'warning'
MessageID: 'Simulink:SL_Param_SwitchDoubleDataTypeToAuto'
Message: 'Switching 'double' data type to 'auto' for parameter object'
Handle: [0x1 double]
>> p.DataType
ans =
auto
If you get a different error, please let us know the Release, message text, and message id. You can avoid the warning by casting the Value instead of setting the DataType:
>> q=Simulink.Parameter;
>> q.Value=double(5);
You can also suppress the warning:
>> warning('off', 'Simulink:SL_Param_SwitchDoubleDataTypeToAuto')
and execute:
>> r=Simulink.Parameter;
>> r.Value=5;
>> r.DataType='double';
We have not seen any case in which a parameter Value of type double and parameter DataType ‘auto’ causes incorrect simulation results or incorrect code generation. Please let us know if you see such a problem.
Since R2007b, all blocks honor specifying the DataType of a Simulink.Parameter with a Simulink.AliasType:
>> warning('on', 'Simulink:SL_Param_SwitchDoubleDataTypeToAuto')
>> force_double=Simulink.AliasType;
>> force_double.BaseType
>> s=Simulink.Parameter;
>> s.Value=5;
>> s.DataType='force_double';
Best Answer