As seen in Add Subsystem, it is possible to link to a Subsystem's ports by "drilling down" into it, using the syntax Subsystem-name/.... However, if the designer of the Subsystem changes its internal workings, these ports may be renamed or disappear. An encapsulated Subsystem exposes ports to its parent system, forming an interface that can be referenced without "drilling down. Thus, if the internals of the Subsystem change later, the parent system will not need to be changed.


  • The Subsystem is copied as it is added to the parent, so to change it we must remove it, modify it, and add it again.
  • However, we would never normally go through this cycle - rather, we'd just modify our original script and rerun it. We do it here just for illustration.



This example, along with the others in this section, can be found in the script developing_systems.m in the support/tutorial/system/matlab folder.

M Source Code (against 995)
% section header disp([10 '=== Expose Subsystem ===' 10]) % unlink psys = psys.unlink('sys/dst>out', 'resamp'); % remove the Subsystem from the parent system psys = psys.removesubsystem('sys'); % expose the output port of the Subsystem sys = sys.expose('dst>out', 'out'); % add the modified system to the parent as a Subsystem psys = psys.addsubsystem('sys', sys); % link to this exposed port instead psys = psys.link('sys>out', 'resamp'); % view the parent system psys % execute the system out = brahms(psys, exe); % view the system outputs out

Expected Output

Note the syntax: the Subsystem lists the expose as <-- dst>out, out (expose "dst/out" as "out"); the link in the parent system is from this exposed port to the resamp block, ==> sys>out ==> resamp.

Matlab Console
=== Add Subsystem === -------------------------------- SystemML System -------------------------------- ['Parent System'] -------------------------------- ["sys", 'untitled'] "src" (std/2009/source/numeric) "dst" (std/2009/resample/numeric) ==> src>out ==> dst <-- dst>out, out -------------------------------- "resamp" (std/2009/resample/numeric) ==> sys>out ==> resamp -------------------------------- out = sys: [1x1 struct] resamp: [1x1 struct]