{"id":1128,"date":"2012-08-01T20:53:04","date_gmt":"2012-08-02T01:53:04","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=1128"},"modified":"2012-08-01T20:54:29","modified_gmt":"2012-08-02T01:54:29","slug":"upgrading-simulink-libraries-with-forwarding-tables-and-transformation-functions","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2012\/08\/01\/upgrading-simulink-libraries-with-forwarding-tables-and-transformation-functions\/","title":{"rendered":"Upgrading Simulink Libraries with Forwarding Tables and Transformation Functions"},"content":{"rendered":"<p>If you create and maintain Simulink libraries used in many models, or by many people, I think you will like this R2012a new feature: <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/rn\/bs8esk9.html#bs8eszn\">Interactive Library Forwarding Tables for Updating Links<\/a>.<br>\r\n<br><em>Note:<\/em> Library Forwarding Tables have been around for a long time, but they used to be available through the command line only.  This new feature in R2012a adds an enhanced interface to this old capability: <tt>set_param('Lib1', 'ForwardingTable', {{'Lib1\/A', 'Lib2\/A'} {'Lib1\/B', 'Lib1\/C'}});<\/tt>.<\/p>\r\n\r\n<p><strong>The Challenge<\/strong><\/p>\r\n\r\n<p>Let's say I create a library block with 2 mask parameters, <strong>a<\/strong> and <strong>b<\/strong><\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/initialLibrary.png\" alt=\"Initial Library\" \/><\/p>\r\n\r\n<p>A few weeks or months later, I decide to modify the library and combine <strong>a<\/strong> and <strong>b<\/strong> into only one, equivalent parameter <strong>c<\/strong>:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/modifiedLibrary.png\" alt=\"Modified Library\" \/><\/p>\r\n\r\n<p>The next time a user will open his model using this library block, he will receive a warning like the following:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/libraryWarning.png\" alt=\"Warning: In instantiating linked block 'testMdl\/Subsystem' : My\r\nNew Block block (mask) does not have a parameter named 'a\" \/><\/p>\r\n\r\n<p>and the value for the new parameter <strong>c<\/strong> will be the default coming from the library. <strong>a<\/strong> and <strong>b<\/strong> will be lost.<\/p>\r\n\r\n<p><strong>The Solution<\/strong><\/p>\r\n\r\n<p>To avoid loosing values for <strong>a<\/strong> and <strong>b<\/strong> stored in the model, you can write a transformation function.<\/p>\r\n\r\n<p>First, go to the <strong>File<\/strong> menu of the library. In the Library Properties dialog, go to the Forwarding Table tab and add an entry for your block:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/libraryProperties.png\" alt=\"Library forwarding table\" \/><\/p>\r\n\r\n<p>Create a transformation function to process the value of <strong>a<\/strong> and <strong>b<\/strong> stored in the model and create the new value for <strong>c<\/strong>.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/tranformation_function.png\" alt=\"Example transformation function\" \/><\/p>\r\n\r\n<p>I recommend going through the documentation section <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/ug\/brkngxr-1.html#brkngxr-6\">Making Backward-Compatible Changes to Libraries<\/a> for more details and examples of the syntax to use in this function.<\/p>\r\n\r\n<p>With this transformation applied, your users will be happy to see that the values they had previously set for <strong>a<\/strong> and <strong>b<\/strong> are kept:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/transformation_result.png\" alt=\"Before and After\" \/><\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>Of course, the example above is very simple, to highlight the concept. Give a look at the documentation section <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/ug\/brkngxr-1.html#brkngxr-6\">Making Backward-Compatible Changes to Libraries<\/a> and let us know if this functionality is useful for you by leaving a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=1128&#comment\">comment here<\/a><\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>If you create and maintain Simulink libraries used in many models, or by many people, I think you will like this R2012a new feature: Interactive Library Forwarding Tables for Updating Links.\r\nNote:... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2012\/08\/01\/upgrading-simulink-libraries-with-forwarding-tables-and-transformation-functions\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,69,16],"tags":[281,45,25],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1128"}],"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=1128"}],"version-history":[{"count":20,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1128\/revisions"}],"predecessor-version":[{"id":1180,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1128\/revisions\/1180"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=1128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=1128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=1128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}