Change the Number of Inputs
This example shows how to set the number of inputs for a System object™ with and
without using getNumInputsImpl.
If you have a variable number of inputs or outputs and you intend to use the System
object in Simulink®, you must include the getNumInputsImpl or getNumOutputsImpl
method in your class definition.
These examples show modifications for the number of inputs. If you want to change the
number of outputs, the same principles apply.
As with all System object Impl methods, you always set the getNumInputsImpl and
getNumOutputsImpl method's access to protected because they are internal methods
that are never called directly.
Allow up to Three Inputs
This example shows how to write a System object that allows the number of inputs to
vary.
Update the stepImpl method to accept up to three inputs by adding code to handle one,
two, or three inputs. If you are only using this System object in MATLAB,
getNumInputsImpl and getNumOutputsImpl are not required.
Full Class Definition
classdef AddTogether < matlab.System
% Add inputs together
methods (Access = protected)
function y = stepImpl(~,x1,x2,x3)
switch nargin
case 2
y = x1;
case 3
y = x1 + x2;
case 4
y = x1 + x2 + x3;
otherwise
y = [];
end
34 System object Usage and Authoring