www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@sweepsetfilter/modifyResampling.m

    function obj = modifyResampling(obj, index, varNames, resampleExp)
%MODIFYRESAMPLING Modify some of the resampling functions
%
%  SSF = MODIFYRESAMPLING(SSF, INDEX, VARNAMES, RESAMPLEEXP)
%
%  VARNAMES and RESAMPLEEXP can be a string if INDEX is a scalar. Otherwise
%  they must be cell arrays the same size as INDEX.
%  
%  If VARNAMES is empty, then the variables are kept invariant.
%
%  Examples:
%    ssf = modifyResampling(ssf, 2, 'X', 'f(x)')
%    ssf = modifyResampling(ssf, 2, {'X','Y'}, 'f(x)')
%    ssf = modifyResampling(ssf, [2, 3], {{'X','Y'}, 'Z'}, {'f(x)', 'g(x)'})
%
%  See also SWEEPSETFILTER, SWEEPSETFILTER/ADDRESAMPLING,
%  SWEEPSETFILTER/REMOVERESAMPLING. 

%  Copyright 2000-2005 The MathWorks, Inc. and Ford Global Technologies, Inc.



% Ensure that variable names are in a cell array
if ~iscell( varNames )
    varNames = {varNames};
elseif isempty( varNames )
    varNames = {''}; % cell array of 1 empty string
end

% Ensure that resample expressions are in a cell array
if ~iscell( resampleExp )
    resampleExp = {resampleExp};
end

% Check that all the inputs agree on size
sz_index       = size( index );
sz_varNames    = size( varNames );
sz_resampleExp = size( resampleExp );
if prod( sz_index ) == 1 && prod( sz_resampleExp ) == 1 && ...
        prod( sz_varNames ) ~= 1 && iscellstr( varNames )
    % Have a command like: modifyResampling(ssf, 2, {'X','Y'}, 'f(x)')
    varNames = {varNames(:)'};
elseif ~all( sz_index == sz_varNames ) || ~all( sz_index == sz_resampleExp )
    error(message('mbc:sweepsetfilter:InvalidArgument6'));
end

% Get the resampling structure from the object
resampling = obj.resampling;

% Iterate through the resamplings to change
for i = 1:numel( index )
    ii = index(i);
    % Store the string given by the user
    resampling.resampleExp{ii} = resampleExp{i};
    % Update the variables to apply this resampling to
    if ~isempty( varNames{i} )
        if iscell( varNames{i} )
            % We need to ensure that the variables are stored in rows.
            resampling.varNames{ii} = varNames{i}(:)';
        else
            % Single variable stored as a string
            resampling.varNames{ii} = varNames{i};
        end
    end
end

% Put the resampling structure back into the object
obj.resampling = resampling;

% Update the object with the new resampling
obj = updateResampling( obj, [] );