function mplayclose(arg)
%MPLAYCLOSE Close any or all MPlay GUI instances.
%   MPLAYCLOSE closes the current MPlay viewer.
%
%   MPLAYCLOSE('all') closes all MPlay instances.

%   Copyright 2005-2007 The MathWorks, Inc.
%   $Revision: 1.1.6.1 $  $Date: 2010/08/30 02:55:10 $

if nargin<1
    m = uiscopes.find(0);
else
    if ~strcmpi(arg,'all')
        error(generatemsgid('InvalidInput'), 'Argument must be ''all''.');
    end
    m = uiscopes.find;
end

% Return early if there are no scopes open.
if isempty(m), return; end

m = find(m, '-depth', 0, '-function', @(h) isMPlay(h));

if ~isempty(m)
    close(m);
end

%% ------------------------------------------------------------------------
function b = isMPlay(h)

b = strcmp(h.getAppName(true), 'MPlay');

% [EOF]
