function Out = set(RespObj,varargin)
%SET  Set properties of Response Object RESPOBJ.
%
%   SET(RESPOBJ,'Property',VALUE) sets the property of RESPOBJ specified
%   by the string 'Property' to the value VALUE.
%
%   SET(RESPOBJ,'Property1',Value1,'Property2',Value2,...) sets multiple 
%   Response Object property values with a single statement.
%
%   SET(RESPOBJ,'Property')  displays possible values for the specified
%   property of RESPOBJ.
%
%   SET(RESPOBJ)  displays all properties of RESPOBJ and their admissible 
%   values.
%
%   See also GET.

%   Authors: A. Potvin, 3-1-94
%   Revised: P. Gahinet, 4-1-96
%            A. DiVergilio, 10-27-99
%   Revised for Response Objects: K. Gondoly, 1-5-98
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.25 $  $Date: 2000/06/14 20:07:31 $

% Generic SET method for all response objects
% RE: Assumes RespObj is a child object! Use PVSET for @response objects

ni = nargin;
no = nargout;
if ~isa(RespObj,'response'),
   % Call built-in SET. Handles calls like set(gcf,'user',ss)
   builtin('set',RespObj,varargin{:});
   return
elseif no & ni>2,
   error('Output argument allowed only in SET(RespObj) or SET(RespObj,Property).');
end

% Get public properties and their assignable values
if ni<=2,
   [AllProps,AsgnValues,DocInd] = pnames(RespObj);
else
   AllProps = pnames(RespObj);
end

% Handle various syntax
if ni==1,
   % SET(RespObj) or S = SET(RespObj)
   if no,
      Out = cell2struct(AsgnValues(DocInd),AllProps(DocInd),1);
   else
      disp(pvformat(AllProps(DocInd),AsgnValues(DocInd)))
   end

elseif ni==2,
   % SET(RespObj,'Property') or STR = SET(RespObj,'Property')
   % Return admissible property value(s)
   try
      [Property,imatch] = pnmatch(varargin{1},AllProps);
      if no,
         Out = AsgnValues{imatch};
      else
         disp(AsgnValues{imatch})
      end
   catch 
      error(lasterr)
   end

else
   % SET(RespObj,'Prop1',Value1, ...)
   name = inputname(1);
   if rem(ni-1,2)~=0,
      error('Property/value pairs must come in even number.')
   end
   
   % Match specified property names against list of public properties and
   % set property values at object level
   try
      for i=1:2:ni-1,
         varargin{i} = pnmatch(varargin{i},AllProps);
      end
      RespObj = pvset(RespObj,varargin{:});
   catch
      error(lasterr)
   end
   
   % POST-SET (for children objects only)
   if RespObj.RefreshAxisLimits
      % Update axis limits
      RespObj = axeslims(RespObj);
      RespObj.RefreshAxisLimits = 0;
   end
   
   % Make sure UIcontextMenu's UserData has latest version of RespObj 
   % RE: Assumes RespObj is a child object!
   builtin('set',RespObj.UIContextMenu.Main,'UserData',RespObj)
   
   % Finally, assign RespObj in caller's workspace
   if no
      Out = RespObj;
   elseif ~isempty(name),
      assignin('caller',name,RespObj)
   end
end
