%% Map Atomic Subchart Variables to Bus Elements
% This model contains two Sine Wave blocks that supply signals through a
% bus to a chart. 

% Copyright 2018-2020 The MathWorks, Inc.

model = 'sf_atomic_subcharts_map_bus_fixed';
load_system(model)

% Delete all annotations at the top level of the model
ah = find_system(model, 'FindAll', 'on', 'type', 'annotation');
for i = 1:length(ah)
   ao = get_param(ah(i), 'Object');
   ao.delete;
end

open_system(model)

%%
% The chart consists of two linked atomic subcharts from the same library.
% Both atomic subcharts contain saturator logic to convert an input sine
% wave to an output square wave of the same frequency.
%
% <<../sf_atomic_subcharts_map_bus_subchart.png>>

% g2074387
% open_system([model '/Chart/A'])

%%
% If you simulate the model, you get an error because the |u1| inputs in
% each subchart do not map to any variables in the main chart. To edit the
% mapping for |u1| in each subchart:
%
% # Right-click subchart A and select *Subchart Mappings*.
% # Under *Input Mapping*, specify the main chart symbol for |u1| to be
% the first element in the bus: |BusIn.u1|.
% # Click *OK*.
% # Repeat for subchart B, specifying the main chart symbol for |u1| to be
% the second element in the bus: |BusIn.u2|.
%
% When you run the model again, you get these results.

sim(model);
open_system([model '/Scope'])