%% State Control Block in Synchronous Mode
% This model contains a MATLAB function block that defines the function
% |fcn|, described previously. The input |u| is a square wave with values
% of 1 and -1.

% Copyright 2018-2019 The MathWorks, Inc.

%% 

mdl = 'hdlcoder_init_persistent_var_fixed';
open_system(mdl);

%%
% In the MATLAB function block:
%
% * The initial value of the persistent variable |n| depends on the input
% |u|.
% * The |return| statement interrupts the normal control flow of the
% function. 
%
% Because the model contains a State Control block in |Synchronous| mode,
% the initialization results in an error.
%
% If you modify the function so it initializes |n| independently of the
% input, then you can simulate an error-free model.

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