Stateflow graphical function won't take variables in ml expression

1 回表示 (過去 30 日間)
Wilfred
Wilfred 2011 年 9 月 14 日
I'm trying to construct a graphical function x=choosefrom(y), with x and y integers, which should return a random integer x, 1<x<=y. I thought it was simple: just create one transition with condition {x=ml('randi(y,1,1)')}. But executing the statechart that uses this function results in an error message "eval of matlab expression randi(y,1,1) didn't return anything (#358) While executing: Transition Guarding Condition."
However, it does work as intended if I create multiple transitions [y==2]{x=ml('randi(2,1,1)')}, [y==3]{x=ml('randi(3,1,1)')}, etc., out of the first junction. But this way, I am limited to a predefined range for y with separate transitions for each value of y, which is impractical.
Thus, it seems I cannot use variables as arguments for randi. This limitation seems to be specific for graphical functions - it doesn't apply to using randi in Stateflow actions anywhere else in the statechart. Why is this, and how could I resolve it?

採用された回答

Wilfred
Wilfred 2011 年 9 月 15 日
I figured out that I should have used {x=ml.randi(y,1)} instead of using the ml('') notation. Now it works.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeComplex Logic についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by