What's the difference between stateflow and simulink?
Asked Answered
W

7

8

As far as I know, stateflow and simulink are often used at the same time, and are both environments developed by MathWorks, who make Matlab. May I know what's the difference between them?

Wishful answered 18/9, 2012 at 14:8 Comment(4)
Have you tried reading the MathWorks webpages? What other things have you looked into? What's your current understanding, can you explain? What do you see as the similarities and common points? What are you still confused about? Answering these questions will help other people give you the help you need.Bedfellow
Yeah, I have read the webpages. In my opinion, they are all the sate machines. there is state, transition. The difference is only that there is continuous variables in the simulink.Wishful
My point was that your question was a bit open-ended, didn't expose your current understanding and sounded like you wanted us to read the product descriptions for you. I've used MatLab, but neither stateflow nor simulink. My understanding is that stateflow is a particular domain-specific environment within simulink, used specifically for discrete logic, whereas simulink is a more general package with a wide variety of tools. I'm no expert, though. Perhaps someone else is. I've added other tags to bring your question to a wider audience.Bedfellow
I can't believe this question isn't more highly upvoted. Great question. Mathworks has some descriptions here too, but the answers below are better: MathWorks: StateflowEmmons
O
14

Simulink is largely a controls oriented solution. It graphically depicts math like products, sums, integrals, etc. However, it's conditional logic facility is lacking. Any kind of if construct quickly becomes terse and unmanageable in my opinion. I've seen many models, and there is a clear line here where Simulink should end and Stateflow should start.

Stateflow deals extremely well with logic and, of course, state machines. Now with the addition of the Simulink Function blocks within Stateflow, we have a powerful combination to allow the state machine in Stateflow direct the rest of the program.

As far as functionality goes, they are both functionally complete, meaning anything you can code in C, you can code in Simulink or Stateflow. However, I would not recommend coding a PID loop in Stateflow, but it's possible. You could also easily create a state machine in Simulink, but I'd advise against it.

As far as code generation; in the beginning of the meld, the Stateflow and Simulink had separate code generators that were sewed together with more Simulink generated C code at code generation time. Then came CGIR (Code Generation Intermediary Representation), which unifies the code generator between Stateflow and Simulink. It came around 2007, and has continued to deliver substantial increases in performance. Generated code has increased in on target performance to a point where companies can use the code in their embedded systems and actually get a performance benefit rather than take a small hit. Also, the time to generate the code has also decreased substantially. CGIR is a replacement for the Target Language Compiler, however, never fear, TLC API will still be available, perhaps forever for those who have developed massive libraries of proprietary code generation libraries.

Hope this helps, let me know if something sounds fishy or if I need to clarify.

Ogdoad answered 18/9, 2012 at 15:36 Comment(0)
C
2

Quoting a Stateflow Webinar:

Simulink is used to respond to continuous changes in dynamic changes. Stateflow is used to respond to instantaneous changes in dynamic changes. Real-world systems have to respond to both continuous and instantaneous changes. Use both Simulink and Stateflow so that you can use the right tool for the right job. Examples: Suspensions dynamics of a car are modelled with Simulink whereas, the gear transmission is modelled with Stateflow.

Cheney answered 30/10, 2015 at 9:40 Comment(0)
B
0

Learn more about Stateflow in general at: http://www.mathworks.com/products/stateflow/examples.html

Stateflow has been updated for making it very easy to create state machines and flow charts in R2012b.

The major updates include a new graphical editor, state transition tables, MATLAB as the action language and an integrated debugger. Find short videos for these features and how they can be used at:

http://www.mathworks.com/products/stateflow/whatsnew.html

best, Siddharth

Bracy answered 19/10, 2012 at 21:26 Comment(0)
C
0

I'm also currently involved with both simulink and stateflow. Till now I did everything in Simulink but once you have to implement logic( if, case) your model becomes visually difficult to be analysed after coding. But I think theoretically you can do everything also just in Simulink (correct me if I'm wrong).

The answer of macduff explains very good the differences.

Regards, GR

Curlpaper answered 8/11, 2013 at 12:38 Comment(0)
L
0

Complex state machine: Stateflow
Complex mathematical process: Simulink blocks
Others: both of Stateflow and Simulink are fine

Lodger answered 14/4, 2018 at 2:57 Comment(0)
L
0

I have worked on both on simulink and state flow environment both are Matlab tool. When u want to design a reactive system or event driven system at that time we should prefer stateflow instead of simulink. because we can control an event in stateflow in better way compare to simulink .though debugging is easy in simulink but readability and code generation are easy in stateflow.

Legendary answered 20/6, 2018 at 6:11 Comment(0)
M
0

Another major benefit of Stateflow is the integration and usage of external C code. This can be done by selecting the Action Language C within the Chart settings. As commonly known the user can include external Code within the "Simulation Target" options. While a normal Simulink model need small workarounds to access the external C code (ceval(), Simulink.Parameter for globals etc.), Stateflow can directly access functions, defines, etc. Problems like array of buses/structs can also be avoided by coding these arrays in external code. For a lot of use cases I love the flexibility to directly interact with C code within Stateflow.

Montespan answered 15/9, 2022 at 9:49 Comment(1)
This answer would fit better as a supporting comment to another answer rather than an answer by itself :-)Priority

© 2022 - 2024 — McMap. All rights reserved.