Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new Stateflow chart in a Simulink block.
Simulink
chart = Stateflow.Chart([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using Stateflow.Chart as the argument (it's the return type)
Using Stateflow.State which is for creating states
Forgetting that Simulink.Model can also work but Block is listed
✗ Incorrect
Stateflow.Chart requires a Simulink.Block (or Simulink.Model) as the parent to create a new Stateflow chart object.
2fill in blank
mediumComplete the code to add a state named 'Idle' to the chart.
Simulink
idleState = Stateflow.State([1], 'Name', 'Idle');
Attempts:
3 left
💡 Hint
Common Mistakes
Using model or system which are unrelated
Using block which is not a Stateflow container
✗ Incorrect
The state must be added to the chart object.
3fill in blank
hardFix the error in the code to set the initial state of the chart to 'Idle'.
Simulink
chart.[1] = idleState;Attempts:
3 left
💡 Hint
Common Mistakes
Using StartState or DefaultState which do not exist
Using EntryState which is not a chart property
✗ Incorrect
The property to set the initial state is InitialState.
4fill in blank
hardFill both blanks to create a transition from 'Idle' to 'Active' state.
Simulink
transition = Stateflow.Transition([1], [2]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using chart or model instead of states
Reversing source and destination states
✗ Incorrect
Transitions are created between source and destination states.
5fill in blank
hardFill all three blanks to set the condition and action of the transition.
Simulink
transition.Condition = '[1]'; transition.Action = '[2]'; transition.[3] = true;
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid property names
Setting Condition or Action incorrectly
Not enabling the transition
✗ Incorrect
Condition is a logical expression, Action is an assignment, Enabled activates the transition.
