{"id":3300,"date":"2019-04-15T05:57:33","date_gmt":"2019-04-15T10:57:33","guid":{"rendered":"https:\/\/blogs.mathworks.com\/loren\/?p=3300"},"modified":"2019-04-21T04:28:27","modified_gmt":"2019-04-21T09:28:27","slug":"stateflow-charts-come-to-matlab","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/loren\/2019\/04\/15\/stateflow-charts-come-to-matlab\/","title":{"rendered":"Stateflow Charts Come to MATLAB!"},"content":{"rendered":"<div class=\"content\"><!--introduction--><p>I have been a little bit slow in announcing some of the coolest new features\/products in the most recent release, R2019a. Why should you even care?  What does <a href=\"https:\/\/www.mathworks.com\/products\/stateflow.html\">Stateflow<\/a> do?  It allows you show the logic behind the work you are doing.  You may say \"I can already do that in MATLAB with if\/else statements, switch\/case statements, etc.  And you can.  But as you add extra conditions, the nesting of code and at least my ability to fully comprehend it can create a lot of mental overhead and burden.  With state charts, you can encapsulate extra condition behavior without quite some much clutter, and yet high clarity.<\/p><!--\/introduction--><p>You can get a quick idea from this picture, showing how to design the system of a lamp with the option to have the light blinking at different rates.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/images\/loren\/2019\/sflamp.png\" alt=\"\"> <\/p><p>Guy beat me to the punch announcing <a href=\"https:\/\/blogs.mathworks.com\/simulink\/2019\/04\/08\/executing-stateflow-charts-in-matlab\/\">Stateflow charts for MATLAB<\/a>.  Rather than replicate his wonderful post, I do want to encourage you to read about it.  I also encourage you to watch a <a href=\"https:\/\/www.mathworks.com\/videos\/using-stateflow-to-provide-the-logic-for-a-matlab-app-1550669336454.html\">small video<\/a> which, I hope, will give you some ideas.<\/p><p>One of the main MATLAB applications we see state charts helping with include the logic that controls Apps.  I am quite sure there are others?  Do have see a place in your workflow that a state chart can help with?  Let me know <a href=\"https:\/\/blogs.mathworks.com\/loren\/?p=3300#respond\">here<\/a>.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_7735fcbc615245e3a1816a457a5f07f2() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='7735fcbc615245e3a1816a457a5f07f2 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 7735fcbc615245e3a1816a457a5f07f2';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2019 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_7735fcbc615245e3a1816a457a5f07f2()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2019a<br><\/p><\/div><!--\r\n7735fcbc615245e3a1816a457a5f07f2 ##### SOURCE BEGIN #####\r\n%% Stateflow Charts Come to MATLAB!\r\n% I have been a little bit slow in announcing some of the coolest new\r\n% features\/products in the most recent release, R2019a. Why should you even\r\n% care?  What does <https:\/\/www.mathworks.com\/products\/stateflow.html\r\n% Stateflow> do?  It allows you show the logic behind the work you are\r\n% doing.  You may say \"I can already do that in MATLAB with if\/else\r\n% statements, switch\/case statements, etc.  And you can.  But as you add\r\n% extra conditions, the nesting of code and at least my ability to fully\r\n% comprehend it can create a lot of mental overhead and burden.  With state\r\n% charts, you can encapsulate extra condition behavior without quite so\r\n% much clutter, and yet high clarity.\r\n%% \r\n% You can get a quick idea from this picture, showing how to design the\r\n% system of a lamp with the option to have the light blinking at different\r\n% rates.\r\n%\r\n% <<sflamp.png>>\r\n%\r\n%%\r\n% Guy beat me to the punch announcing\r\n% <https:\/\/blogs.mathworks.com\/simulink\/2019\/04\/08\/executing-stateflow-charts-in-matlab\/\r\n% Stateflow charts for MATLAB>.  Rather than replicate his wonderful post,\r\n% I do want to encourage you to read about it.  I also encourage you to\r\n% watch a\r\n% <https:\/\/blogs.mathworks.com\/simulink\/2019\/04\/08\/executing-stateflow-charts-in-matlab\/\r\n% small video> which, I hope, will give you some ideas.\r\n%%\r\n% One of the main MATLAB applications we see state charts helping with include\r\n% the logic that controls Apps.  I am quite sure there are others?  Do have\r\n% see a place in your workflow that a state chart can help with?  Let me\r\n% know <https:\/\/blogs.mathworks.com\/loren\/?p=3300#respond here>.\r\n##### SOURCE END ##### 7735fcbc615245e3a1816a457a5f07f2\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"http:\/\/blogs.mathworks.com\/images\/loren\/2019\/sflamp.png\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction--><p>I have been a little bit slow in announcing some of the coolest new features\/products in the most recent release, R2019a. Why should you even care?  What does <a href=\"https:\/\/www.mathworks.com\/products\/stateflow.html\">Stateflow<\/a> do?  It allows you show the logic behind the work you are doing.  You may say \"I can already do that in MATLAB with if\/else statements, switch\/case statements, etc.  And you can.  But as you add extra conditions, the nesting of code and at least my ability to fully comprehend it can create a lot of mental overhead and burden.  With state charts, you can encapsulate extra condition behavior without quite some much clutter, and yet high clarity.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/loren\/2019\/04\/15\/stateflow-charts-come-to-matlab\/\">read more >><\/a><\/p>","protected":false},"author":39,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[74,6],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/3300"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/comments?post=3300"}],"version-history":[{"count":5,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/3300\/revisions"}],"predecessor-version":[{"id":3315,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/3300\/revisions\/3315"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/media?parent=3300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/categories?post=3300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/tags?post=3300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}