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!!
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!