www.gusucode.com > mbc 工具箱 matlab 源码程序 > mbc/@mbcmodel/@project/CopyData.m

    function newD = CopyData(P, D)
%COPYDATA Make a copy of some data.
% 
%   NEWDATA = COPYDATA(PROJECT, DATA) copies the requested data object and
%   returns the NEWDATA.
% 
%   NEWDATA = COPYDATA(PROJECT, INDEX) copies the data at index INDEX from
%   the project and returns the NEWDATA.
%
%   See also mbcmodel.project.CreateData, mbcmodel.project.RemoveData.

%   Copyright 2004-2010 The MathWorks, Inc.


% Get the project
MP = P.Object;
% Get the list of data from the project
pAllData = dataptrs(MP);
% Is D an mbcmodel.data object or and integer
if isnumeric(D)
    try
        pData = pAllData(D);
    catch
        error('mbc:mbcmodel:project:InvalidArgument', ...
            'An integer index into the data array must be supplied');
    end
elseif isa(D, 'mbcmodel.data')
    index = findptrs(D.pGetPointerInstance, pAllData);
    % Did we find it?
    if index < 1
        error(message('mbc:mbcmodel:project:InvalidArgument1'));
    end
    pData = pAllData(index);
else
    error(message('mbc:mbcmodel:project:InvalidArgument2'));
end
% Duplicate the appropriate dataset and cast to an ssf
data = sweepsetfilter(pData.info);
% Change label after casting to ssf to ensure the testplan bit is removed
data = set(data, 'Label',  ['Copy of ' pData.get('label')]);
% Put the new data on the heap
pcData = xregpointer(data);
% Update the project datalist with the new sweepsetfilter object
addData(MP, pcData);

newD = mbcmodel.data(pcData,P);