view m-toolbox/classes/@ao/min.m @ 22:b11e88004fca database-connection-manager

Update collection.fromRepository
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents f0afece42f48
children
line wrap: on
line source

% MIN computes the minimum value of the data in the AO.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DESCRIPTION: MIN computes the minimum value of the data in the AO.
%
% CALL:        ao_out = min(ao_in);
%              ao_out = min(ao_in, pl);
%
% <a href="matlab:utils.helper.displayMethodInfo('ao', 'min')">Parameters Description</a>
%
% VERSION:     $Id: min.m,v 1.31 2011/04/08 08:56:16 hewitson Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function varargout = min(varargin)
  
  % Check if this is a call for parameters
  if utils.helper.isinfocall(varargin{:})
    varargout{1} = getInfo(varargin{3});
    return
  end
  
  % Collect input variable names
  in_names = cell(size(varargin));
  for ii = 1:nargin,in_names{ii} = inputname(ii);end
  
  % Collect all AOs
  [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
  pl              = utils.helper.collect_objects(varargin(:), 'plist');
  
  % Get default parameters
  pl = parse(pl, getDefaultPlist);
  
  % Decide on a deep copy or a modify
  bs = copy(as, nargout);
  

  % Apply method to all AOs
  for j=1:numel(bs)
    skip = false;
    % get min value
    if isa(bs(j).data, 'data3D')
      skip = true;
      warning('!!! Skipping AO [%s]: min doesn''t work for 3D data at the moment', bs(j).name);
    elseif isa(bs(j).data, 'data2D')
      switch lower(find(pl, 'axis'))
        case 'x'
          [mx, idx] = min(bs(j).data.getX);
          my = bs(j).data.getY(idx);
        case 'y'
          [my, idx] = min(bs(j).data.getY);
          mx = bs(j).data.getX(idx);
        otherwise
          error('### The axis must one of ''x'' or ''y''.');
      end
      d = xydata(mx, my);
      d.xunits = bs(j).data.xunits;
      d.yunits = bs(j).data.yunits;
      bs(j).data = d;
    else
      my = min(bs(j).data.getY);
      bs(j).data.setY(my);
    end
    
    if ~skip
      % Set new AO name
      bs(j).name = ['min(' ao_invars{j} ')'];
      % append history
      bs(j).addHistory(getInfo('None'), pl, ao_invars(j), bs(j).hist);
      % clear errors
      bs(j).clearErrors(pl);
    end
  end
  
  
  % Set output
  if nargout == numel(bs)
    % List of outputs
    for ii = 1:numel(bs)
      varargout{ii} = bs(ii);
    end
  else
    % Single output
    varargout{1} = bs;
  end
end

%--------------------------------------------------------------------------
% Get Info Object
%--------------------------------------------------------------------------
function ii = getInfo(varargin)
  if nargin == 1 && strcmpi(varargin{1}, 'None')
    sets = {};
    pl   = [];
  else
    sets = {'Default'};
    pl   = getDefaultPlist;
  end
  % Build info object
  ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.op, '$Id: min.m,v 1.31 2011/04/08 08:56:16 hewitson Exp $', sets, pl);
end

%--------------------------------------------------------------------------
% Get Default Plist
%--------------------------------------------------------------------------
function plout = getDefaultPlist()
  persistent pl;  
  if exist('pl', 'var')==0 || isempty(pl)
    pl = buildplist();
  end
  plout = pl;  
end

function pl = buildplist()
  pl = plist.AXIS_2D_PLIST;  
end

% END