www.gusucode.com > simulink 案例源码程序 matlab代码 > simulink/VariantSourceAndVariantSinkBlocksExample.m

    %% Variant Source and Variant Sink Blocks
% Copyright 2010-2016 The MathWorks, Inc.
%%
%%
% Define variant choice regions in the Variant Source
% and Sink blocks based on the block connectivity. The variant choice
% regions are computed by Simulink when you update diagram (*Simulation* >
% *Update Diagram*).
%
% The process of computing the variant choice regions is called |variant
% condition propagation| . The Variant Source block provides variation on the
% source of a signal, and the Variant Sink blocks provides variation on the
% destination (sink) of a signal.
%
% Consider a model containing two Variant Source blocks ( |Variant Source1| ,
% |Variant Source2|) and a Sink block ( |Variant Sink| ).
%%
%
model = fullfile(matlabroot,'help', 'toolbox', 'simulink', 'examples', 'slexVariantSourceAndSink');
open_system(model)
%%
%
% The variant conditions at the inports and outports of Variant Source and
% Sink blocks, respectively, determine the activation and deactivation of the
% blocks connected to them. To view the annotations and the variant
% conditions, click *Display* > *Blocks* > *Variant Conditions*.
%%
% <<../SrcSnk_model_1.png>>
%%
% Let's analyze the variant conditions and the block activation state. 
%%
% 
% * In |Variant Source1|, when |W==1|, the |Sine3| block is active, and when
% |W==2|, the |Sine4| block is active.
% * In |Variant Source2|, when |V==1|, the Sine1 block is active, and when
% |V==2|, the |Add1| block is active.
% * At |Add1| block the condition propagation continues making |Variant
% Source1| block to be active only when the |V==2|. This further propagates
% to |Sine3| block and |Sine4| block, making the |Sine3| block active at
% |V==2 && W==1| the |Sine3| block active at |V==2 && W==2|, respectively.
% * The |Gain3| block is active when either |V==1| or |V==2|, and hence the
% condition |V==2||W==1|. The variant condition is further propagated to
% |Scope1| and |Out1|.
% * The blocks connected to the outport of |Variant Sink| are active when
% |W==1| (|Gain5|), or |W==2| (|Sine|, |Subtract|, |Terminator|).
% * The |Sum| block illustrates two key concepts in variant condition propagation:
% ** Signals are only variant if explicitly marked or when all paths can be
% proven to be variant. To make the |Sine Wave|, |Sum|, |Out2| variant, 
% place a Single-Input Single-Output Variant Source before Out2 (or
% after the Sine Wave).
% ** Reading an inactive signal is equivalent to reading ground. When |W
% ~= 1|, then the bottom input to the |Sum| block is inactive and |Out2 =
% Sine6 + ground|.
%%
% If you select the *Analyze all choices during update diagram and generate
% preprocessor conditionals* parameter for the Variant Source and Variant
% Sink block, the generated code contains the code for the active and the
% inactive (|#if COND|). If this parameter is not selected, then code is
% generated only for the active choices.