{"id":2445,"date":"2013-07-31T11:30:41","date_gmt":"2013-07-31T16:30:41","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=2445"},"modified":"2013-08-01T11:43:03","modified_gmt":"2013-08-01T16:43:03","slug":"referencing-configuration-sets-for-model-reference","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2013\/07\/31\/referencing-configuration-sets-for-model-reference\/","title":{"rendered":"Referencing Configuration Sets for Model Reference"},"content":{"rendered":"<p>A few weeks ago I described the possibility of <a href=\"https:\/\/blogs.mathworks.com\/seth\/2013\/07\/08\/quickly-switching-model-configuration-sets\/\">storing more multiple configuration sets in a single model<\/a>.<\/p>\r\n\r\n<p>Today we will do the opposite: <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/sharing-a-configuration-set-for-multiple-models.html\">Sharing one configuration set among multiple models.<\/a><\/p>\r\n\r\n<p><strong>Reference Configuration Set<\/strong><\/p>\r\n\r\n<p>By default, in Simulink, the configuration of a model is stored in the model file itself.<\/p>\r\n\r\n<p>However when you have a hierarchy of referenced models, those models must have similar configuration sets. Instead of having each model storing its own configuration, it is possible to have all models refer to a single configuration set.<\/p> \r\n\r\n<p>To begin, setup the configuration you want in one model and convert it to a configuration reference:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/convertingToReference.png\" alt=\"Converting to reference configuration\" \/><\/p>\r\n\r\n<p>A dialog will allow you to specify the name of the configuration set and give you the possibility to save it to a MAT-file or a MATLAB script.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/saveConfigDialog.png\" alt=\"Specifying the name and file of the configuration set\" \/><\/p>\r\n\r\n<p>Note that if you do not save the configuration set at this time, it is always possible to save it later using <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/simulink.blockdiagram.saveactiveconfigset.html\">Simulink.BlockDiagram.saveActiveConfigSet<\/a><\/p>\r\n\r\n<p>Once the configuration object is in the base workspace, you can configure all your child models to refer to it:<\/p>\r\n\r\n<p><em><strong>Update:<\/strong> This can be done by right-clicking on the top model configuration reference and selecting <strong>Propagate to Referenced Models<\/strong><\/em><\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/referenceConfig.png\" alt=\"Multiple model referencing the same configuration\" \/><\/p>\r\n\r\n<p>That way if the configuration needs to change, you will need to make the change in only one place.<\/p>\r\n\r\n<p><strong>Creating Variants of a common configuration set<\/strong><\/p>\r\n\r\n<p>In a hierarchy of referenced models, it is common to want all the child models to have almost the same configuration, except a few parameters. For example, in the following model I want the three child models to have all the same configuration, except I want <tt>child3.slx<\/tt> to execute at a different sample time.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/modelForConfigRef.png\" alt=\"Multiple model referencing similar configuration\" \/><\/p>\r\n\r\n<p>To make that happen, I stored a configuration named <tt>myConfig<\/tt> in a MATLAB script <tt>configFile.m<\/tt>. In an initialization script that I execute before running my model (for example the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/model-callbacks.html\">model PreLoadFcn callback<\/a>), I copy this configuration set and modify the parameter I need.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/variantConfigset.png\" alt=\"Creating a configuration set based on an existing configuration set\" \/><\/p>\r\n\r\n<p>That way, I can configure <tt>child3.slx<\/tt> to refer to <tt>myConfigTS2<\/tt>. If, in the future, I need to change a parameter in all the child models, I only need to do it once in <tt>configFile.m<\/tt>. When my initialization script will create <tt>myConfigTS2<\/tt>, it will automatically inherit this change.<\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>Do you take advantage of configuration reference? Let us know by leaving a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=2445&#comment\">comment here<\/a><\/p>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/variantConfigset.png\" onError=\"this.style.display ='none';\" \/><\/div><p>A few weeks ago I described the possibility of storing more multiple configuration sets in a single model.\r\n\r\nToday we will do the opposite: Sharing one configuration set among multiple... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2013\/07\/31\/referencing-configuration-sets-for-model-reference\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[66,24],"tags":[335,456],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/2445"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=2445"}],"version-history":[{"count":48,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/2445\/revisions"}],"predecessor-version":[{"id":2538,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/2445\/revisions\/2538"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=2445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=2445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=2445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}