Integrating a state machine in Matlab
It is possible for your model to have its state machine logic entirely exported for it to be integrated into Matlab.
How to export the state machine (.m)
- First of all, you need to have your state machine already generated.
- Once this is done, you can open the specific state machine that you want to export, by either:
- Clicking on a state in a user story diagram.
- Accessing it from the overview.
- Right-click on the background of the state machine diagram to open the contextual menu.
attention
This will not work if you right-click on a state, or even on the state machine itself. You need to Right-click outside of all elements.
- In the contextual menu, click on Edit, then on Export State Machine.

- This should generate a new file (.m) in your export folder.
What is exported
The file you end up with is Matlab script (.m). It will include a function with:
- Several inputs: Those are all the variables used in your model, as well as the current state.
- Output: The output will be the next state.
attention
It is recommended when modeling, that you only use your own created variables in the state machine, and not the ones automatically generated by the flows parameters.
This process will allow you to integrate the state machine logic, while processing other parts of your model in Matlab/Simulink.