Effacer les filtres
Effacer les filtres

To workspace block does not read 0 correctly

2 vues (au cours des 30 derniers jours)
Matthias
Matthias le 19 Nov 2014
Commenté : Orion le 19 Nov 2014
Dear Community!
I am reading double values consisting of 0s and 1s via the "to workspace" into the workspace (the 0s are checked to equality to 0). However some of the 0 values are not loaded as 0 into the workspace but as values in the range in between 2^-15 to 2^-16 (above the resolution of double...?). Also changing the sample time changes the positions of the wrong entries.
If you need more information don't hesitate to inform me.
Thank you very much!!

Réponses (1)

Orion
Orion le 19 Nov 2014
This is a classic problem of numerical precision.
several ways to treat it :
- before sending your data in the workspace, convert it in logical or integer.
- in post-treating, convert your data , such as : simout = bool(simout)
- instead of comaring to 0, compare to a reference value (0 in your case) and epsilon
, in this last way, you consider that a tiny difference (10^-16) is OK.
instead of
simout==0
search for
abs(simout-0) < 10^-14
  2 commentaires
Matthias
Matthias le 19 Nov 2014
Thank you for your suggestions!
Unfortunately none of these are applicable in my case because the underlying model is quite fixed. I wonder if there is some setting to prevent this precision problem because the input data is binary really 0 but the workspace data has some binary value unequal to 0. Double values are unfortunately obligatory in our environment.
BTW, background is that these values as you can assume used as booleans for logical blocks. Of course we could mask them and add some functionality to handle these problems, but this would really be the last solution. We are working with this environment for years and until now never faced this problem...?
Orion
Orion le 19 Nov 2014
If you're data is supposed to be used in logical condition, it shouldn't be calculated as a double in the model at all ? It seems to me there is a modeling error (even if this kind of modeling is current, it's not recommended).
Also, Did you change of Matlab Version ?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Simulink Functions dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by