Simulink, how to do conditional execution inside stateflow

170 次查看(过去 30 天)
Our team want to conditional execute code inside one single state. To be executed every execution. I found no applicable examples.
Such as following does not compile:
% code
entry:
x = y;
during:
if a == 12
b = c;
end
Junctions with conditional inside one single state does compile, but will default only execute at entry. To be executed every execution, an arrow outside the state is required and cause all other entry-code to be executed, that is not wanted. It need to be easy-read visible code, not hidden in function call:
In c-code this is simple and common to write. What is the technique in simulink, without creating "fake-states" that is not functionally required states ?

回答(1 个)

Akhilesh Mishra
Akhilesh Mishra 2017-7-10
编辑:Akhilesh Mishra 2017-7-10
From my understanding of the question, it seems that you wish to execute some specific conditional code inside a state chart. For your workflow, you can try using sub-states within your main state. This will not require you to run the entire state again for one conditional code. The details on sub-states can be found in the following link -
To understand the transitions in the substates you can refer to the following documentation link- https://www.mathworks.com/help/releases/R2017a/stateflow/ug/moving-between-different-levels-of-hierarchy-with-supertransitions.html#f9-58101
A relevant example can be found in the link mentioned below, where inside the state 'powerOn', there are two sub-states 'up' and 'down'. The state 'powerOn' can have its own code different from the code in sub-states. https://www.mathworks.com/help/stateflow/examples/modeling-a-dc-motor-in-stateflow.html

类别

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