classdef (CaseInsensitiveProperties, TruncatedProperties) pwlinear <...
      idPiecewiseLinear & idobsolete.idnlfun
   %PWLINEAR Piecewise linear nonlinearity estimator object constructor.
   % pwlinear is deprecated. Use idPiecewiseLinear instead.
   
   % Usage:
   %   P = PWLINEAR
   %       Create a piecewise linear nonlinearity estimator object with
   %       default number of units (10) and unknown breakpoints.
   %
   %   P = PWLINEAR('BreakPoints',BP)
   %       Create a piecewise linear nonlinearity estimator object with
   %       break points specified by matrix BP. The number of units is
   %       equal to the number of columns in BP.
   %
   %       BP: Can be specified as a row vector or a matrix with two rows.
   %       When specified as a 2-by-n matrix: [x_1,...x_n;y_1,...y_n], the
   %       first row specifies the initial input values, while the second
   %       row specifies the corresponding initial values of the
   %       nonlinearity. When BP is specified as a single row, it is taken
   %       to represent the input values [x_1,...x_n], while the
   %       nonlinearity values are initialized using zeros:
   %       y_1 = y_2 = ... = y_n = 0.
   %
   %   P = PWLINEAR('NumberOfUnits',n)
   %       Create a piecewise linear nonlinearity estimator object with
   %       number of units (= number of breakpoints) = n.
   %
   % Properties:
   %       NumberOfUnits: stores the number of units in the nonlinearity
   %       estimator. This is equal to the number of breakpoints (default: 10).
   %
   %       BreakPoints: stores the breakpoints and the corresponding
   %       nonlinearity values. If empty (= []), the values are
   %       initialized using estimation data during model estimation.
   %
   %       The nonlinearity properties can be get and set by
   %       subreferencing, as in: P.br = BP. If BP here is a row vector,
   %       the values are interpreted as new x-values (input breakpoints),
   %       while the y-values (nonlinearity values) are set to zero.
   %
   % Description:
   %       P is a nonlinearity object, describing the piece-wise linear
   %       function y = F(x), where y and x are scalars and y_k = F(x_k),
   %       k=1,...,n and linearly interpolated between these values. The
   %       value F(x) is computed by using the "evaluate" command, as in:
   %       Values = evaluate(P,x).
   %
   %       Note that F(x) is linear also to the left and right of the
   %       extreme breakpoints. The slope of these extensions can be a
   %       complicated function of x_i, y_i. Note also the internal
   %       representation of the breakpoints is different, which may
   %       explain minor deviations from the set values in some cases.
   %
   % Typical use: Piecewise linear nonlinearity is employed typically in
   %   Hammerstein-Wiener (IDNLHW) models. Example:
   %   model = NLHW(Data,Orders,pwlinear('Br',[-1:0.1:1]),[])
   %   estimates an IDNLHW model using pwlinear as its input nonlinearity.
   %   The nonlinearity is initialized at the given breakpoints, which are
   %   then adjusted to data by the estimation function NLHW.
   %
   % See also NLHW, EVALUATE, SATURATION, DEADZONE, POLY1D.
   
   % Copyright 2005-2022 The MathWorks, Inc.
   
   % Author(s): Qinghua Zhang
   %   Technology created in collaboration with INRIA and University Joseph
   %   Fourier of Grenoble - FRANCE
   
   %RE: NumberOfUnits and BreakPoints act as different properties in the
   %implemention.
   
   methods
      function this = pwlinear(varargin)
         %Constructor.
         warning(message('Ident:general:obsoleteClass','pwlinear','idPiecewiseLinear'))
         this = this@idPiecewiseLinear(varargin{:});
      end

      function [Props,AsgnVals] = pnames(~, flag)
         %PNAMES  All PWLINEAR public properties and their assignable
         %values.
         no = nargout;
         ni = nargin;
         readonlyflag = false;
         if ni>1 && ischar(flag)
            if strcmpi(flag, 'readonly')
               readonlyflag = true;
            else
               error(message('Ident:general:wrongPnamesFlag'))
            end
         end
         
         if readonlyflag
            Props = {};
         else
            Props = {'NumberOfUnits', ...
               'BreakPoints'};
         end
         
         if no>1
            if readonlyflag
               AsgnVals = {};
            else
               AsgnVals = {getString(message('Ident:idnlmodel:pwlinearDescr1')),...
                  getString(message('Ident:idnlmodel:pwlinearDescr2'))};
            end
         end
      end
   end
   

   methods (Static, Hidden)
      function sys = loadobj(s)
         %LOADOBJ Load filter for PWLINEAR objects. STATIC METHOD.
         
         % First added in R2021a (version 23)
         % R2021b (version 24): replaced by idPiecewiseLinear; pwlinear
         % becomes subclass of  idPiecewiseLinear

         if isstruct(s)
            updatewarn
            Warn = ctrlMsgUtils.SuspendWarnings; %#ok<NASGU>
         end
         
         v = nlident.internal.FcnIO.utGetVersion(s);
         if isstruct(s) 
            if v<23
               sys = pwlinear;
               if isempty(s.internalParameter)
                  % uninitialized object
                  return
               end
               sys.Parameters_ = s.internalParameter;
               sys.prvNumberOfUnits = s.prvNumberOfUnits;
               if isempty(s.RegressorRange)
                  sys.Input.Range = [-Inf;Inf];
               else
                  sys.Input.Range = s.RegressorRange;
               end
               sys.Input.Mean = 0;
               sys.Output.Range = [-Inf;Inf];
               sys.Output.Mean = 0;
               sys.Utility = s.Utility;
            else
               sys = reload(pwlinear,s,v);
            end
         else
            sys = s;
         end
      end
   end
end
