This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

initialevent

Initialize event variables

Syntax

events 
  when initialevent 
    AssignmentList 
  end 
end

Description

initialevent lets you specify initial values of event variables at the start of simulation. The return data type of initialevent is event, as described in Event Data Type and edge Operator. It returns true once during simulation, right after initialization of continuous variables is finished.

The initialevent keyword is valid only inside a when clause predicate.

Examples

The Asynchronous Sample & Hold block in the Simscape™ Foundation library initializes the event variable y_held, which holds the sampled signal, by using a block parameter.

This example implements an asynchronous sample and hold block where the y_held event variable is initialized based on the value of the input physical signal IC at the start of simulation. Note that there is no need to specify initialization priority for the y_held variable because event variables always have high priority.

component ASHold
% Asynchronous Sample and Hold

inputs
   IC = {0.0, '1'}; % :left
    U = {0.0, '1'}; % :left
    T = {0.0, '1'}; % :left
end;

outputs 
    Y = {0.0, '1'}; % :right
end;

variables (Event = true, Access = private)
     y_held = 0.0;    
end

equations
    Y == y_held;
end

events
    when initialevent
       y_held = IC;
    elsewhen edge(T > 0)
       y_held = U; 
    end
end

end

Introduced in R2017b