www.gusucode.com > mbc 工具箱 matlab 源码程序 > mbc/+mbcutils/@Clipboard/guiCopy.m

    function guiCopy(varargin)
%guiCopy Copy data to the clipboard from a UI.
%
%  guiCopy(data, headers) copies the specified data to the clipboard using
%  the copy method.  If any errors occur then an informative dialog is
%  displayed.
%
%  See also copy.

%   Copyright 2009 The MathWorks, Inc.

NumTries = 5;
Success = false;

while NumTries
    try
        % Clipboard copying may error if the clipboard is unavailable
        mbcutils.Clipboard.copy(varargin{:});
        
        NumTries = 0;
        Success = true;
    catch E
        NumTries = NumTries-1;
        pause(0.1);
    end
end

if ~Success
    msg = ['The data has not been copied because the application was unable ' ...
        'to access the clipboard.  This may be because another application ' ...
        'is locking the clipboard, or because of inadequate security permissions.'];
    % Inform the user that the clipboard copy failed
    waitfor(errordlg(msg, 'Clipboard Error', 'modal'));
end