{"id":9190,"date":"2019-11-15T15:50:51","date_gmt":"2019-11-15T20:50:51","guid":{"rendered":"https:\/\/blogs.mathworks.com\/simulink\/?p=9190"},"modified":"2019-11-18T12:59:57","modified_gmt":"2019-11-18T17:59:57","slug":"new-in-r2019b-subsystem-reference","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2019\/11\/15\/new-in-r2019b-subsystem-reference\/","title":{"rendered":"New in R2019b: Subsystem Reference"},"content":{"rendered":"<p>Today I want to introduce my favorite new feature in MATLAB R2019b: <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2019b\/simulink\/ug\/referenced-subsystem-1.html\">Subsystem Reference<\/a><\/p>\n<p>Let's see what is it, how it works, and when you should be using it.<\/p>\n<p><strong>Creating a Subsystem File<\/strong><\/p>\n<p>In R2019b, we are introducing a new type of block diagram. In addition to model files and library files, it is now possible to create subsystem files:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2019Q4\/ssref_newMenu.png\" alt=\"New menu, including Subsystem Reference\" \/><\/p>\n<p>In the Current Folder window, you can differentiate models, subsystems and libraries by their icon and type:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2019Q4\/threeFileTypes.png\" alt=\"Compare File Types\" \/><\/p>\n<p>From the command-line, if the subsystem is open you can determine what type of block diagram it is using get_param:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2019Q4\/ssref_bdType.png\" alt=\"File Types\" \/><\/p>\n<p>If you need to determine which type of block diagram an slx-file is without opening it or even loading it in memory, you can also use Simulink.MDLInfo:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2019Q4\/ssref_mdlInfo.png\" alt=\"Block diagram Types\" \/><\/p>\n<p><strong>Referencing a Subsystem File<\/strong><\/p>\n<p>The first important thing to realize is that a subsystem file cannot be simulated by itself. If you want to simulate or generate code for the block diagram stored in a subsystem file, you need to reference it in a model.<\/p>\n<p>To reference a subsystem file, you start with a <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2019b\/simulink\/slref\/codereusesubsystem.html\">Subsystem block<\/a>. In R2019b, you will notice that the Subsystem block has a new tab named Subsystem Reference. For convenience, we also added to the Simulink Library a block named Subsystem Reference, which is simply a Subsystem block pre-configured to reference a subsystem file.<\/p>\n<p>Here is an animation where I configure and edit a referenced subsystem. As you can see, entering the subsystem and editing it is as simple and easy as editing a standard subsystem.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2019Q4\/ssRefGo.gif\" alt=\"Editing Subsystem Reference\" \/><\/p>\n<p><strong>Converting an Existing Subsystem<\/strong><\/p>\n<p>If you have an existing model and would like to convert existing subsystems to referenced subsystems, you can simply right-click on the existing subsystem to do the conversion.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2019Q4\/ssref_right_click.png\" alt=\"Converting a Subsystem Reference\" \/><\/p>\n<p><strong>Instance Specific Context Awareness<\/strong><\/p>\n<p>In a way similar to library blocks, it is possible to use multiple instances of the same subsystem in a model, and each instance adapts to its context. The next image shows a model with 3 instances of the same subsystem, one receiving a complex scalar double, one receiving a matrix of 2x3 and the third instance receiving a vector of two integers.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2019Q4\/ssref_multiInstances.png\" alt=\"Converting a Subsystem Reference\" \/><\/p>\n<p><strong>Masking<\/strong><\/p>\n<p>If you want multiple instances of a referenced subsystem to take different parameter values, you can create a mask for the subsystem. This is done from the Modeling tab:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2019Q4\/ssref_mask.png\" alt=\"Masking Subsystem Reference\" \/><\/p>\n<p>This will allow you to pass different parameter values to different instances of the subsystem. The next image shows 3 instances of the same subsystem. The two first take different values for a Gain block, and the last one takes a vector of 2 as input.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2019Q4\/ssref_multiInstance.png\" alt=\"Multiple instances of Subsystem Reference\" \/><\/p>\n<p><strong>When To Use Subsystem Reference?<\/strong><\/p>\n<p>Now the big question: <strong>When to use subsystem reference?<\/strong><\/p>\n<p>The official answer to this question is to read the documentation section <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2019b\/simulink\/ug\/component-based-modeling-guidelines.html\">Component-Based Modeling Guidelines<\/a>. In this section of the documentation, you will find this flow chart:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.mathworks.com\/help\/releases\/R2019b\/simulink\/ug\/component_selection_flowchart.png\" alt=\"Componentization guideline\" \/><\/p>\n<p>Here is my condensed version of how I make this decision. To componentize a model, you need to choose between 3 technologies: libraries, model reference and subsystem reference:<\/p>\n<ul>\n<li><strong>Library:<\/strong> To create a blockset. A blockset is a collection of blocks, distributed to a large audience and rarely changes. To facilitate this use case, libraries provide features like forwarding tables and link management.<\/li>\n<li><strong>Model Reference:<\/strong> To create standalone components with a well-defined rigid interface. Model reference offers many powerful features like accelerator mode, Software-in-the-Loop, Processor-in-the-Loop and protection. If you plan to create large models, model reference will help you scale in a robust and efficient manner.<\/li>\n<li><strong>Subsystem Reference:<\/strong> The simplest way to save part of a model to a separate file. Sometimes I like to describe the subsystem reference as a library that would contain only one subsystem, and stripped down of all the features useful to manage a blockset that are not really needed if you simply want to save the content of a subsystem in a separate file.<\/li>\n<\/ul>\n<p>We also put together <a href=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2019Q4\/BlockDiagramComparison2.pdf\">this table<\/a> that provides more details on the specifics of those three technologies.<\/p>\n<p><strong>Now it's your turn<\/strong><\/p>\n<p>As mentioned above, I strongly recommend that you go through the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2019b\/simulink\/ug\/component-based-modeling-guidelines.html\">Component-Based Modeling Guidelines<\/a> to see all the options available to componentize a model and their implications.<\/p>\n<p>Give subsystem reference a try and let us know what you think in the comments below.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/www.mathworks.com\/help\/releases\/R2019b\/simulink\/ug\/component_selection_flowchart.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>Today I want to introduce my favorite new feature in MATLAB R2019b: Subsystem Reference<br \/>\nLet's see what is it, how it works, and when you should be using it.<br \/>\nCreating a Subsystem File<br \/>\nIn R2019b, we... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2019\/11\/15\/new-in-r2019b-subsystem-reference\/\">read more >><\/a><\/p>\n","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[583],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/9190"}],"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=9190"}],"version-history":[{"count":44,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/9190\/revisions"}],"predecessor-version":[{"id":9309,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/9190\/revisions\/9309"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=9190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=9190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=9190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}