{"id":9753,"date":"2018-05-25T09:00:30","date_gmt":"2018-05-25T13:00:30","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=9753"},"modified":"2018-11-24T12:46:32","modified_gmt":"2018-11-24T17:46:32","slug":"manage-simulink-data-variations-with-simulinkparser","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2018\/05\/25\/manage-simulink-data-variations-with-simulinkparser\/","title":{"rendered":"Manage Simulink Data Variations with simulinkParser"},"content":{"rendered":"<div class=\"content\"><!--introduction--><\/p>\n<p><a href=\"https:\/\/www.mathworks.com\/\/matlabcentral\/fileexchange\/authors\/32620\">Greg&#8217;s<\/a> pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/67142-tmkhoyan-simulinkparser\">simulinkParser<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/11408140-tigran-mkhoyan\">Tigran Mkhoyan<\/a>.<\/p>\n<p>How do you manage different simulation scenarios in your Simulink models?<\/p>\n<p>Tigran provides a simple semantic language to describe how specific blocks in a Simulink model are to be configured, and apply the configuration to the model.<\/p>\n<p><!--\/introduction--><\/p>\n<h3>Contents<\/h3>\n<div>\n<ul>\n<li><a href=\"#7a6d97d5-ff1a-4d59-b264-746f378c2e49\">Define and Apply a Configuration Description<\/a><\/li>\n<li><a href=\"#edca79d7-8d22-4196-b113-be52e3afc222\">Why Is This Configuration Technique Useful?<\/a><\/li>\n<li><a href=\"#a33ebe26-bc4e-4340-83af-805dd91aba29\">Why did I select Tigran&#8217;s Simulink Data Management Tool?<\/a><\/li>\n<li><a href=\"#ce60c04b-9dd7-406b-94bc-7addb3f4a152\">What Should We Add to Simulink for Data Variation Management?<\/a><\/li>\n<\/ul>\n<\/div>\n<h4>Define and Apply a Configuration Description<a name=\"7a6d97d5-ff1a-4d59-b264-746f378c2e49\"><\/a><\/h4>\n<p>Define block parameters:<\/p>\n<p><a href=\"https:\/\/blogs.mathworks.com\/pick\/files\/writeUp_01.png\"><img decoding=\"async\" loading=\"lazy\" width=\"239\" height=\"120\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/writeUp_01.png\" alt=\"\" class=\"alignnone size-full wp-image-9755\" \/><\/a><\/p>\n<p>Reference this configuration from a &#8220;setConfig&#8221; block added to the model<\/p>\n<p><a ref=\"https:\/\/blogs.mathworks.com\/pick\/files\/writeUp_02.png\"><img decoding=\"async\" loading=\"lazy\" width=\"300\" height=\"145\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/writeUp_02-300x145.png\" alt=\"\" class=\"alignnone size-medium wp-image-9757\" \/><\/a><\/p>\n<p>And &#8220;Apply&#8221; the configuration to the model.<\/p>\n<h4>Why Is This Configuration Technique Useful?<a name=\"edca79d7-8d22-4196-b113-be52e3afc222\"><\/a><\/h4>\n<p>This technique enables you to:<\/p>\n<div>\n<ul>\n<li>Manage block and model parameters<\/li>\n<li>Have multiple configurations for the same model<\/li>\n<li>Save the applied configuration to the model directly<\/li>\n<\/ul>\n<\/div>\n<p>This means the model can still execute simulation without the configuration file being present.<\/p>\n<p>There is a school of thought that the values for block parameters should be explict numeric values, and not a reference to a variable in some other workspace. That is, the design in the Simulink model should be defined entirely within that model file.<\/p>\n<style type=\"text\/css\">\n.tg  {border-collapse:collapse;border-spacing:0;}\n.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}\n.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}\n.tg .tg-szh5{font-size:26px;text-align:center}\n<\/style>\n<table class=\"tg\">\n<tr>\n<td class=\"tg-szh5\"><a href=\"https:\/\/blogs.mathworks.com\/pick\/files\/writeUp_03.png\"><img decoding=\"async\" loading=\"lazy\" width=\"300\" height=\"176\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/writeUp_03-300x176.png\" alt=\"\" class=\"alignnone size-medium wp-image-9759\" \/><\/a><\/td>\n<td class=\"tg-szh5\"><\/td>\n<td class=\"tg-szh5\"><a href=\"https:\/\/blogs.mathworks.com\/pick\/files\/writeUp_04.png\"><img decoding=\"async\" loading=\"lazy\" width=\"300\" height=\"176\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/writeUp_04-300x176.png\" alt=\"\" class=\"alignnone size-medium wp-image-9761\" \/><\/a><\/td>\n<\/tr>\n<\/table>\n<p>This certainly simplifies interpretation of an algorithm, and increases the repeatability of simulation results. The drawback is typically the hinderance to scaling the number of simulation scenarios for which a given model might be used is more difficult to manage with &#8220;hard-coded&#8221; values.<\/p>\n<p>This approach bridges that divide somewhat. It provides the robustness of explicit numeric parameter values and the flexibiliy to define several configurations that can be applied to a Simulink model<\/p>\n<h4>Why did I select Tigran&#8217;s Simulink Data Management Tool?<a name=\"a33ebe26-bc4e-4340-83af-805dd91aba29\"><\/a><\/h4>\n<p>Managing data variations in Simulink isn&#8217;t something that has been addressed explicity as part of Simulink.  There are several methods of associating a particular data set to a model, but not much in the way of configuring what data values should be applied in specific scenarios. While scripting in MATLAB gets you a long way, it still requires effort on the part of the user to develop a data variation management strategy.<\/p>\n<p>Tigran&#8217;s entry provides a nice little framework for data variation management for common simulation use cases.<\/p>\n<h4>What Should We Add to Simulink for Data Variation Management?<a name=\"ce60c04b-9dd7-406b-94bc-7addb3f4a152\"><\/a><\/h4>\n<p>Let us know <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=9753#respond\">here<\/a>.<\/p>\n<p><script language=\"JavaScript\"> <!-- \n    function grabCode_ca088e2fdb5e45239aed31206a7350c5() {\n        \/\/ Remember the title so we can use it in the new page\n        title = document.title;\n\n        \/\/ Break up these strings so that their presence\n        \/\/ in the Javascript doesn't mess up the search for\n        \/\/ the MATLAB code.\n        t1='ca088e2fdb5e45239aed31206a7350c5 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\n        t2='##### ' + 'SOURCE END' + ' #####' + ' ca088e2fdb5e45239aed31206a7350c5';\n    \n        b=document.getElementsByTagName('body')[0];\n        i1=b.innerHTML.indexOf(t1)+t1.length;\n        i2=b.innerHTML.indexOf(t2);\n \n        code_string = b.innerHTML.substring(i1, i2);\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\n\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \n        \/\/ in the XML parser.\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\n        \/\/ doesn't go ahead and substitute the less-than character. \n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\n\n        copyright = 'Copyright 2018 The MathWorks, Inc.';\n\n        w = window.open();\n        d = w.document;\n        d.write('\n\n<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\n\\n');\n\n        d.title = title + ' (MATLAB code)';\n        d.close();\n    }   \n     --> <\/script><\/p>\n<p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><a href=\"javascript:grabCode_ca088e2fdb5e45239aed31206a7350c5()\"><span style=\"font-size: x-small;        font-style: italic;\">Get<br \/>\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><\/p>\n<p>      Published with MATLAB&reg; R2018a<\/p>\n<\/div>\n<p><!--\nca088e2fdb5e45239aed31206a7350c5 ##### SOURCE BEGIN #####\n%% Manage Simulink Data Variations with simulinkParser\n% <https:\/\/www.mathworks.com\/\/matlabcentral\/fileexchange\/authors\/32620 Greg's> \n% pick this week is <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/67142-tmkhoyan-simulinkparser \n% simulinkParser> by <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/11408140-tigran-mkhoyan \n% Tigran Mkhoyan>.\n% \n% How do you manage different simulation scenarios in your Simulink models?\n% \n% Tigran provides a simple semantic language to describe how specific blocks \n% in a Simulink model are to be configured, and apply the configuration to the \n% model.\n% \n% \n%% Define and Apply a Configuration Description\n% Define block parameters:\n% \n% \n% \n% Reference this configuration from a \"setConfig\" block added to the model\n% \n% \n% \n% \n% \n% And \"Apply\" the configuration to the model.\n%% Why Is This Configuration Technique Useful?\n% This technique enables you to:\n% \n% * Manage block and model parameters\n% * Have multiple configurations for the same model\n% * Save the applied configuration to the model directly\n% \n% This means the model can still execute simulation without the configuration \n% file being present.\n% \n% There is a school of thought that the values for block parameters should \n% be explict numeric values, and not a reference to a variable in some other workspace. \n% That is, the design in the Simulink model should be defined entirely within \n% that model file. \n% \n% \n% \n%  vs \n% \n% This certainly simplifies interpretation of an algorithm, and increases \n% the repeatability of simulation results. The drawback is typically the hinderance \n% to scaling the number of simulation scenarios for which a given model might \n% be used is more difficult to manage with \"hard-coded\" values.\n% \n% This approach bridges that divide somewhat. It provides the robustness \n% of explicit numeric parameter values and the flexibiliy to define several configurations \n% that can be applied to a Simulink model\n% \n% \n%% Why did I select Tigran's Simulink Data Management Tool?\n% Managing data variations in Simulink isn't something that has been addressed \n% explicity as part of Simulink.  There are several methods of associating a particular \n% data set to a model, but not much in the way of configuring what data values \n% should be applied in specific scenarios. While scripting in MATLAB gets you \n% a long way, it still requires effort on the part of the user to develop a data \n% variation management strategy.\n% \n% Tigran's entry provides a nice little framework for data variation management \n% for common simulation use cases.\n%% What Should We Add to Simulink for Data Variation Management?\n% Let us know.\n##### SOURCE END ##### ca088e2fdb5e45239aed31206a7350c5\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/writeUp_01.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>\nGreg&#8217;s pick this week is simulinkParser by Tigran Mkhoyan.<br \/>\nHow do you manage different simulation scenarios in your Simulink models?<br \/>\nTigran provides a simple semantic language to describe how&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2018\/05\/25\/manage-simulink-data-variations-with-simulinkparser\/\">read more >><\/a><\/p>\n","protected":false},"author":36,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,24,28],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/9753"}],"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\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=9753"}],"version-history":[{"count":9,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/9753\/revisions"}],"predecessor-version":[{"id":10326,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/9753\/revisions\/10326"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=9753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=9753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=9753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}