Documentation Center

  • Trial Software
  • Product Updates

Change Number of Step Inputs or Outputs

This example shows how to specify two inputs and two outputs for the step method.

If you do not specify the getNumInputsImpl and getNumOutputsImpl methods, the object uses the default values of 1 input and 1 output. In this case, the user must provide an input to the step method.

    Note:   You should only use getNumInputsImpl or getNumOutputsImpl methods to change the number of System object™ inputs or outputs. Do not use any other handle objects within a System object to change the number of inputs or outputs.

To specify no inputs, you must explicitly set the number of inputs to 0 using the getNumInputsImpl method. To specify no outputs, you must explicitly return 0 in the getNumOutputsImpl method.

You always set the getNumInputsImpl and getNumOutputsImpl methods access to protected because they are internal methods that users do not directly call or run.

Update the Algorithm for Multiple Inputs and Outputs

Update the stepImpl method to accept a second input and provide a second output.

methods (Access=protected)
   function [y1,y2] = stepImpl(~,x1,x2)
      y1 = x1 + 1
      y2 = x2 + 1;
   end
end

Update the Associated Methods

Use getNumInputsImpl and getNumOutputsImpl to specify two inputs and two outputs, respectively.

methods (Access=protected)
   function numIn = getNumInputsImpl(~)
      numIn = 2;
   end
   
   function numOut = getNumOutputsImpl(~)
      numOut = 2;
   end
end

Complete Class Definition File with Multiple Inputs and Outputs

classdef AddOne < matlab.System
%ADDONE Compute output values two greater than the input values
  
  % All methods occur inside a methods declaration.
  % The stepImpl method has protected access
  methods(Access=protected)
    
    function [y1,y2] = stepImpl(~,x1,x2)
      y1 = x1 + 1;
      y2 = x2 + 1;
    end
    
    % getNumInputsImpl method calculates number of inputs
    function num = getNumInputsImpl(~)
      num = 2;
    end
    
    % getNumOutputsImpl method calculates number of outputs
    function num = getNumOutputsImpl(~)
      num = 2;
    end    
  end  
end

See Also

|

Related Examples

More About

Was this topic helpful?