Providing Maximum Value as Initial Value for Single Precision Signal Causes Error due to Quantization

I have a model which has an input signal with data type "single". This signal has the initial value which is same as maximum value. (10.3 for this case). When I evaluate the model, I get the error stating that quantized initial value is greater than maximum value.
  • Below is screenshot of definition of signal and error I get during model update.
I believe the cause of the error is that maximum value is evaluated with data type "double" while initial value is evaluated with data type "single", and 10.3 with single precision is greater than 10.3 with double precision as shown below.
As data dictionary only accepts finite real double scalar value for maximum and minimum value, I was not able to find good solution for the problem.
  • How can I work around this problem?
  • Is there any method to set maximum and minimum value of the signal with datatype single?
I have attached sample model and associated data dictionary which reproduces the problem. The problem happens for "sample_input" signal.

 Accepted Answer

I had similar issues with this. I have requested the Mathworks to do an enhancement but have not seen it in place yet.
The problem arises when casting a number from double to single. The "precision loss" occurred and Simulink reports it as warning or error. It is true that the "precision loss" could happen but I think the software should give an option whether the user wants to ignore the double-to-single type cast precision loss.
What version of MATLAB are you using? The message seems to be different than what I saw in several versions of MATLAB/Simulink. Typically, you can go to Simulink configuration parameters, Diagnostics, Data Validity, Parameters, change the setting for "Detect precision loss". If you set it as "warning" or "none", you could pass the model update with or without even the warning messages.
You could also try to set the Initial value as single(10.3). In my case, the warning disappeared by doing this.

4 Comments

Hi Fangjun,
I am using R2016b. My model has "Detect precision loss" set as warning. I have tried to set initial value as single(10.3) which I still get error.
I believe the issue is that maximum value is evaluated as double. I have tried to set it as single(10.3), but the Data Dictionary does not accept as it only allows finite real double scalar value.
Yes. R2016b seems to report this error but R2017b apparently did not, although the document indicates both do the same validation.
Contact the Mathworks tech support to see if they can help you. I can't get rid of this error in R2016b except setting the maximum value as double(single(10.3))
Thank you for quick response. I will contact MathWorks tech support.
I got the response from MathWorks that this problem is resolved in R2017a ( Link to release note ). For R2016b, the workaround is what Fangjun has suggested.

Sign in to comment.

More Answers (0)

Products

Release

R2016b

Community Treasure Hunt

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

Start Hunting!