setup
Prepares a System object for execution, locking it, before the first call to step.
Category: Programming > Classes
Syntax
setup(obj, x1, ..., xn)
Runs the object's setupImpl using inputs like those that step will receive, and locks the object.
Description
step calls setupImpl by itself on its first call, so setup is only needed when initialization must happen at a chosen moment, for example before a timing loop. After setup the object is locked and the next step skips the initialization.
Calling setup on an object that is already locked is an error; call release first.
Input arguments
obj- A System object.
x1, ..., xn- Example inputs, used to fix their data types and sizes. They are not processed.
Example
Initializing before the first step
writelines([ ...
"classdef Counter < matlab.System", ...
" properties", " Total = 0", " end", ...
" methods (Access = protected)", ...
" function setupImpl(obj)", " obj.Total = 100;", " end", ...
" function y = stepImpl(obj, u)", " obj.Total = obj.Total + u;", " y = obj.Total;", " end", ...
" function releaseImpl(obj)", " disp('released')", " end", ...
" end", "end"], 'Counter.m');
c = Counter;
c.Total
setup(c);
c.Total
isLocked(c)
Output
ans = 0
ans = 100
ans = logical
1
setupImpl of the example class sets Total to 100.