Take the 2-minute tour ×

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?

share|improve this question
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. –  AndrewC Sep 18 '12 at 14:21
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. –  sweetyBaby Sep 18 '12 at 14:25
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. –  AndrewC Sep 18 '12 at 14:47
add comment

3 Answers

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.

share|improve this answer
add comment

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:


best, Siddharth

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer


