www.gusucode.com > mbc 工具箱 matlab 源码程序 > mbc/+mbcutils/@Clipboard/copy.m
function copy(data,cheaders) %copy Copy data to system clipboard % % copy(data) copies the data to the clipboard. If the data is a numeric % matrix it will be converted to a tab-delimited string. % copy(data,cheaders) adds header strings to a numeric matrix. % % See also: guiCopy % Copyright 2000-2009 The MathWorks, Inc. and Ford Global Technologies, Inc. if isnumeric(data) if ndims(data)>2 % can't copy multi-dim stuff onto clipboard else if nargin<2 cheaders={}; end if ~isempty(data) % create tab-delimited string that Excel will understand str=i_tostring(data,cheaders); clipboard('copy',str); end end else clipboard('copy',data); end function s=i_tostring(data,cheaders) if ~isempty(cheaders) s=sprintf('%s\t',cheaders{:}); s(end)=sprintf('\n'); else s=''; end % copy numbers to clipboard as tab-delimited with a char(10) between rows c=size(data, 2); fmtstr=repmat('%f\t',1,c); fmtstr(end)='n'; s=[s sprintf(fmtstr,data')]; s(end)=[];