In State flow, consider state 1 and state 2 with transitions between them. if there are 2 actions in state 1, is there a way to execute action 1 only the first time state 1 is entered ? during re-entry to state 1, only action 2 should be executed

1 view (last 30 days)
In State flow, consider state 1 and state 2 with transitions between them. if there are 2 actions in state 1, is there a way to execute action 1 only the first time state 1 is entered ? during re-entry to state 1, only action 2 should be executed and I am using the data from action 1 in sub-states. entry: command would execute the action every time a particular state is entered.

Answers (1)

Will Nitsch
Will Nitsch on 3 May 2017
You could create some variable and set it equal to 0 (say 'a = 0') in the initialization code, and then, in the entry function of the block have an if else statement like so:
entry:
if(~a)
doFunction1(some arguments);
a = 1;
else
doFunction2(some other arguments);
end
during:
doFunction3(even more arguments);
bind: a;

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!