필터 지우기
필터 지우기

Why does Stateflow evaluate the condition [x >= (1/2)] differently from [x >= 0.5]?

조회 수: 1 (최근 30일)
I have created a minimal example (available here: http://dl.dropbox.com/u/99981625/fraction_in_condition.mdl) consisting of a single chart with a single state (A) which increments an output variable x in steps of 0.1. A transition from A to A is conditioned on [x >= y], where y is a literal constant. A conditional action resets x to zero. The output variable x is declared as a real double scalar and is given an initial value of zero. If y is the literal "1/2", the condition mysteriously evaluates true even when the debugger shows that x == 0 (or x < 0.5, in general). The conditional action resets the value of x, causing it to remain zero for all time. On the other hand, if y is the literal "0.5", then x increments from 0 to 0.5 before being reset to zero. I expected both conditions to behave as in this second example. Why don't they?
Thanks for any ideas.

채택된 답변

Siddharth Shankar
Siddharth Shankar 2012년 11월 4일
편집: Siddharth Shankar 2012년 11월 4일
If I had to guess, I would think that 1/2 results in integer division which always yields 0, and this is then cast to double (0.0) for the comparison, by which time the damage is done. If this hypothesis is correct ;), 1.0/2.0 should show you the same behavior as 0.5.
  댓글 수: 1
Brian B
Brian B 2012년 11월 4일
MATLAB has made me casual about my literals! I should have thought about that. Making the suggested change produces the expected behavior.
It is good to know that Stateflow does not treat literals as doubles by default, as MATLAB does. Thanks for the insight.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Complex Logic에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by