This example shows the concept of a graphical function and how it can be used to simplify your Stateflow® model. In this example, we pass two inputs in the Stateflow chart. The first input is a sine wave with magnitude 1 and a frequency of 2*pi and the second input is that same sine wave but inverted. The Stateflow charts output only the positive values of both the input signals and also saturate the signal at a value of 0.5.
In the first chart, 'Without Graphical Functions', the output is defined directly within the substate. The Normal state is activated first, and the output is set equal to the normal_input. When the normal_input is greater than 0.5, the output is set equal to 0.5. When the normal_input becomes negative (<0), then a state transition occurs, and the output is redefined the same way within the Inverse state, except that the inverse_input is used.
In the 'With Graphical Functions' chart, the output is defined by calling the graphical function. Instead of defining the saturation transition (where the output remains at the 0.5 value) within the states, we only define it once in the graphical function. Although it is not as evident in this simple example, when more conditions and parameters are introduced, and the output needs to be defined in multiple states, graphical functions allow you to simplify your model.