{"id":2536,"date":"2010-02-26T14:00:11","date_gmt":"2010-02-26T14:00:11","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2010\/02\/26\/synchronizing-a-matlab-gui-and-a-simulink-model\/"},"modified":"2010-03-11T23:27:31","modified_gmt":"2010-03-11T23:27:31","slug":"synchronizing-a-matlab-gui-and-a-simulink-model","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2010\/02\/26\/synchronizing-a-matlab-gui-and-a-simulink-model\/","title":{"rendered":"Synchronizing a MATLAB GUI and a Simulink Model"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\">Jiro<\/a>'s pick this week is <a href=\"\"><tt>Simulink GUI Synchronization<\/tt><\/a> by our fellow MathWorker <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/76890\">Will Campbell<\/a>.\r\n   <\/p>\r\n   <p>Here's a little something new. We've been mostly looking at MATLAB entries in this blog, but today we'll take a look at a\r\n      Simulink example. Even though this is a simple example, I find this very useful and pedagogical. Imagine that you want to\r\n      build a graphical user interface that controls your Simulink model (<i>You know how I'm all about GUIs!<\/i>). This is not uncommon and can be accomplished by using functions like set_param and get_param. But what if you want to be\r\n      able to control the model directly through Simulink as well as through the MATLAB interface? In that case, you want to make\r\n      sure that the interface accurately reflects the current state of the model.\r\n   <\/p>\r\n   <p>In this example, Will shows how you can create a MATLAB GUI that not only drives and manipulates your Simulink model, but\r\n      also stays synchronized to the current state. You too can now drive and manipulate your Simulink model from either environment!\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/sl_gui_screenshot.png\"> <\/p>\r\n   <p><b>Comments<\/b><\/p>\r\n   <p><a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2536#respond\">Tell us<\/a> how you use MATLAB and Simulink together.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_eb59588409114d298d8d42830d2ab402() {\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='eb59588409114d298d8d42830d2ab402 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' eb59588409114d298d8d42830d2ab402';\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        author = 'Jiro Doke';\r\n        copyright = 'Copyright 2010 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 author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\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      \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_eb59588409114d298d8d42830d2ab402()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.9<br><\/p>\r\n<\/div>\r\n<!--\r\neb59588409114d298d8d42830d2ab402 ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\r\n% Jiro>'s pick this week is\r\n% <\r\n% |Simulink GUI Synchronization|> by our fellow MathWorker\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/76890\r\n% Will Campbell>.\r\n%\r\n% Here's a little something new. We've been mostly looking at MATLAB\r\n% entries in this blog, but today we'll take a look at a Simulink example.\r\n% Even though this is a simple example, I find this very useful and\r\n% pedagogical. Imagine that you want to build a graphical user interface that\r\n% controls your Simulink model (_You know how I'm all about GUIs!_). This\r\n% is not uncommon and can be accomplished by using functions like\r\n% set_param and get_param. But what if you want to be able to control the\r\n% model directly through Simulink as well as through the MATLAB interface?\r\n% In that case, you want to make sure that the interface accurately\r\n% reflects the current state of the model.\r\n%\r\n% In this example, Will shows how you can create a MATLAB GUI that not only\r\n% drives and manipulates your Simulink model, but also stays synchronized\r\n% to the current state. You too can now drive and manipulate your Simulink\r\n% model from either environment!\r\n%\r\n% <<sl_gui_screenshot.png>>\r\n%\r\n% *Comments*\r\n%\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2536#respond Tell us> how you use\r\n% MATLAB and Simulink together.\r\n##### SOURCE END ##### eb59588409114d298d8d42830d2ab402\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   Jiro's pick this week is Simulink GUI Synchronization by our fellow MathWorker Will Campbell.\r\n   \r\n   Here's a little something new. We've been mostly looking at MATLAB entries in this blog,... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2010\/02\/26\/synchronizing-a-matlab-gui-and-a-simulink-model\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,24],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2536"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2536"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2536\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}