%% Map Atomic Subchart Parameters to Expressions
% For parameters in an atomic subchart, you can specify a constant
% expression or an expression that depends on one or more parameters in the
% main chart.
%
% For example, this model contains two Sine Wave blocks that supply input
% signals to a chart.

% Copyright 2018-2020 The MathWorks, Inc.

%% 

model = 'sf_atomic_subcharts_map_parameter_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 subchart 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_parameter_subchart.png>>

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

%%
% If you simulate the model, you get an error because the parameter |T| is
% undefined. To fix this error, specify an expression for |T| to evaluate
% in the main chart:
%
% # Right-click subchart A and select *Subchart Mappings*.
% # Under *Parameter Mapping*, as the value for |T|, enter |-1|.
% # Click *OK*.
% # Repeat for subchart B, specifying the value of |T| as |2|.
%
% <<../mapping_for_parameter_example.png>>

%%
% When you run the model again, you get these results.

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