%% Generate Structured Text Code for Variable-Size Signals
% Deploy applications such as machine learning models to your target PLC
% by generating code for variable-size signals. Verify the generated structured
% text code by generating test bench code and importing the generated test bench
% code into your target IDE.

% Copyright 2021 The MathWorks, Inc.

%% Model Description
% The model consists of a simple MATLAB(R) Function Block, Stateflow(R)
% chart and a Simulink(R) subsystem. The MATLAB(R) Function Block generates
% a variable one-dimensional array based on whether the input signal |u| is
% greater than or less than zero. The Stateflow(R) chart has two
% states that transition between assigning the output variable |y|
% to the input variable |u| and multiplying |y| by two. The Simulink(R)
% subsystem has a |Sum of Elements| block that sums all the elements in
% |y|.
%%
%% Simulate and Generate Structured Text Code
% Open the Simulink model.
mdl = 'vardim_ex';
open_system(mdl)
%%
% To generate structured text code for the |Subsystem| block, use the |plcgeneratecode|
% command.
%
% plcgeneratecode([mdl '/Subsystem']);
%%
% Close the model
close_system(mdl)
