Using Stateflow to Provide the Logic for a MATLAB App
In this video, we use Stateflow® to graphically design state machine and timing logic that would be difficult to implement textually for a Lamp App created with MATLAB® App Designer.
Published: 20 Feb 2019
You can create a standalone State Chart from MATLAB that is stored as a .sfx file and can be instantiated as MATLAB Object for use in applications.
This Lamp Logic State Chart is part of an app created with App Designer.
Notice the animation of the off state indicating it is active. The off state contains the MATLAB code to directly turn off the lamp and disable the mode and blink speed widgets in the GUI.
When we switch the lamp on in the GUI, the on event is sent to the Stateflow chart causing the state machine to leave the off state and enter the on state. This state has the MATLAB code to enable the mode and blink speed widgets in the GUI. We can also see the sub-state “solid” is active and contains the code to turn the lamp on.
Here, we can see the code written in App Designer to generate the on and off events that are used in the Stateflow chart.
The lamp has two modes of operation: solid, which it is in now, and blinking. Selecting the blinking mode causes the lamp to start to blink. Notice transitions between the on and off states that are inside the blinking state keep occurring. The MATLAB code in these states turns the lamp in the GUI on and off.
By changing the blink speed, we can slow down or speed up the time between the transitions. These transitions occur based on a MATLAB timer that is automatically generated because the after keyword has been used.
This example shows how a Stateflow chart can be used as part of an App. However, Stateflow charts can be used to represent complex logic and state machines in any MATLAB program without writing deeply nested if-else or switch-case statements.
Featured Product
Stateflow
Up Next:
Related Videos:
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)