Documentation Center

  • Trial Software
  • Product Updates

Best Practices for Defining System Objects

System objects are optimized for iterative processing. Use System objects when you need to call the step method multiple times or process data in a loop. When defining your own System object™, use the following suggestions to ensure that your code runs efficiently.

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

  • Define parameters that should not change in a locked object as Nontunable properties.

  • If the number of System object inputs and outputs does not change or if you explicitly list the inputs and outputs in the stepImpl method instead of using varargin or varargout, you do not need to implement the getNumInputsImpl method.

  • Variables that do not need to retain their values between calls and are used in setupImpl, stepImpl, or any other single method should have local scope for that method.

  • Properties that are accessed more than once in the stepImpl or updateImpl and outputImpl methods should be cached as local variables inside that method. Iterative calculations using cached local variables run faster than calculations that must access the object's properties. When the stepImpl calculations complete, you can save the local cached results back to the System object's properties. You should copy frequently used tunable properties into private properties.

For best practices for including System objects in code generation, see System Objects in MATLAB Code Generation.

Was this topic helpful?