function value = getappdata(h, name)
%GETAPPDATA Get value of application-defined data.
%  VALUE = GETAPPDATA(H, NAME) gets the value of the
%  application-defined data with name specified by NAME in the
%  object with handle H.  If the application-defined data does
%  not exist, an empty matrix will be returned in VALUE.
%
%  VALUES = GETAPPDATA(H) returns all application-defined data
%  for the object with handle H.
%
%  See also SETAPPDATA, RMAPPDATA, ISAPPDATA.

%  Copyright 1984-2003 The MathWorks, Inc.
%  $Revision: 1.11.4.4.2.1 $  $Date: 2005/01/08 23:41:42 $


error(nargchk(1, 2, nargin));

if length(h) ~= 1
   error('H must be a single handle.');
end

value = get(h, 'ApplicationData');
if nargin == 2
    la = lasterror;
    % Code execution will break here if an incorrect NAME is specified
    % because we return [] thru' a try catch mechanism. Disabling the
    % dbstop handling or checking for the field is too expensive. Best
    % option is to make this into a built-in.
    try
        value = value.(name);
    catch
        value = [];
        lasterror(la);
    end
end

