To workspace block does not read 0 correctly

1 次查看(过去 30 天)
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!!

回答(1 个)

Orion
Orion 2014-11-19
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 个评论
Matthias
Matthias 2014-11-19
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 2014-11-19
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 ?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by