classdef (StrictDefaults)slexVarSizeMATLABSystemFindIfSysObj < matlab.System
%slexVarSizeMATLABSystemFindIfSysObj Find input elements that satisfy the given condition.
%     The condition is specified in the block dialog. Both outputs 
%     are variable-sized vectors.
%

%#codegen
% Copyright 2015 The MathWorks, Inc.

properties (Nontunable)
    % Condition Condition to test
    Condition (1, :) char {mustBeMember(Condition, {'~=', '==', '>=', '<='})} = '~=';
end

properties
   % ConditionValue Apply condition against value
   ConditionValue = 0;
end


  methods
    function this = slexVarSizeMATLABSystemFindIfSysObj(varargin)
        setProperties(this, nargin, varargin{:});
    end
  end
  
  methods(Access=protected)
    
      function validatePropertiesImpl(obj)
          if (numel(obj.ConditionValue)~=1)
             error(message('simdemos:MLSysBlockMsg:ValueForConditionShouldBeScalar'));
          end
      end

      function [linearIndices, elements] = stepImpl(obj, u)
          switch obj.Condition
            case '~='
                linearIndices = find(u ~= obj.ConditionValue);
            case '=='
                linearIndices = find(u == obj.ConditionValue);
            case '>='
                linearIndices = find(u >= obj.ConditionValue);
            case '<='
                linearIndices = find(u <= obj.ConditionValue);
          end
          elements = u(linearIndices);
      end
    
    function num = getNumOutputsImpl(~)
        num = 2;
    end

    function [sz1, sz2] = getOutputSizeImpl(obj)
        % Maximum length of linear indices and element vector is the
        % number of elements in the input
        if (~isempty(propagatedInputSize(obj, 1)))
            numelIn = prod(propagatedInputSize(obj, 1));
            sz1 = numelIn;
            sz2 = numelIn;
        else
            sz1 = [];
            sz2 = [];
        end
    end
    
     function [fz1, fz2] = isOutputFixedSizeImpl(~)
      %Both outputs are always variable-sized
      fz1 = false;
      fz2 = false;
    end
    
    function [dt1, dt2] = getOutputDataTypeImpl(obj)
        dt1 = 'double'; %Linear indices are always double values
        dt2 = propagatedInputDataType(obj, 1);
    end
    
    function [cp1, cp2] = isOutputComplexImpl(obj)
        cp1 = false; %Linear indices are always real values
        cp2 = propagatedInputComplexity(obj, 1);
    end
    
  end
  
end
