Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Specify System Block Input and Output Names

This example shows how to specify the names of the input and output ports of a System object™–based block implemented using a MATLAB System block.

Define Input and Output Names

This example shows how to use getInputNamesImpl and getOutputNamesImpl to specify the names of the input port as "source data" and the output port as "count."

If you do not specify the getInputNamesImpl and getOutputNamesImpl methods, the object uses the stepImpl method input and output variable names for the input and output port names, respectively. If the stepImpl method uses varargin and varargout instead of variable names, the port names default to empty strings.

methods (Access=protected)
   function inputName = getInputNamesImpl(~)
          inputName = 'source data';
   end
   
   function outputName = getOutputNamesImpl(~)
          outputName = 'count';
   end
end

Complete Class Definition File with Named Inputs and Outputs

classdef MyCounter < matlab.System
  
   %MyCounter Count values above a threshold
     
    properties
       Threshold = 1
    end
    properties (DiscreteState)
       Count
    end
 
    methods
       function obj = MyCounter(varargin)
          setProperties(obj,nargin,varargin{:});
       end
    end
 
    methods (Access=protected)
       function setupImpl(obj, u)
          obj.Count = 0;
       end
       function resetImpl(obj)
          obj.Count = 0;
       end
       function y = stepImpl(obj, u)
          if (u > obj.Threshold)
             obj.Count = obj.Count + 1;
          end
          y = obj.Count;
       end
       function inputName = getInputNamesImpl(~)
          inputName = 'source data';
       end
       function outputName = getOutputNamesImpl(~)
          outputName = 'count';
       end
    end
end

See Also

| | |

Related Examples

More About

Was this topic helpful?