MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Tips for Defining System Objects


A System object is a specialized MATLAB object that is optimized for iterative processing.
Use System objects when you need to run an object multiple times or process data in a
loop. When defining your own System object, use the following suggestions to help your
System object run more quickly.

General



  • Define all one-time calculations in the setupImpl method and cache the results in a
    private property. Use the stepImpl method for repeated calculations.

  • Specify Boolean values using true or false instead of 1 or 0 , respectively.

  • If the variables in a method do not need to retain their values between calls, use local
    scope for those variables in that method.


Inputs and Outputs



  • Some methods use the stepImpl algorithm inputs as their inputs, such as
    setupImpl, updateImpl, validateInputsImpl,
    isInputDirectFeedThroughImpl, and processInputSizeChangeImpl. The
    inputs must match the order of inputs to stepImpl, but do not need to match the
    number of inputs. If your implementation does not require any of the inputs to the
    System object, you can leave them all off.

  • For the getNumInputsImpl and getNumOutputsImpl methods, if you set the return
    argument from an object property, that object property must have the Nontunable
    attribute.


Using ~ as an Input Argument in Method Definitions


All methods, except static methods, expect the System object handle as the first input
argument. You can use any name for your System object handle. The code inserted by the
MATLAB Editor menu uses obj.

In many examples, instead of passing in the object handle, ~ is used to indicate that the
object handle is not used in the function. Using ~ instead of an object handle prevents
warnings about unused variables.

34 System object Usage and Authoring

Free download pdf