www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mbctree/@wksptreenode/canAddData.m

    function [OK, newNumRec] = canAddData(node, ss, numRec)
%CANADDDATA Whether the data at this node can be added to the data to
%import.
%
%   [OK, NEWNUMREC] = CANADDDATA(NODE, SS, NUMREC)

%   Copyright 2006-2015 The MathWorks, Inc.

% Default starting position
OK = false;
newNumRec = -1;
if nargin<2
    ss = sweepset;
    numRec = 0;
end

switch node.Type
    case {'ROOT', 'STRUCT'}
        children = node.getChildren;
        childOK = false(1,length(children));
        childNumRec = zeros(1,length(children));
        % Iterate over each child
        for i=1:length(childOK)
            % Ask the child
            [childOK(i), childNumRec(i)] = canAddData( children(i), ss, numRec );
        end
        OK = ~isempty(childOK) && all(childOK) && all(childNumRec == childNumRec(1));
        if OK
            newNumRec = childNumRec(1);
        end
    case 'VECTOR'
        newNumRec = length(node.LocalData);
        OK = (numRec == newNumRec || numRec == 0) && newNumRec > 0;
    case 'ARRAY'
        newNumRec = size(node.LocalData, 1);
        OK = (numRec == newNumRec || numRec == 0) && newNumRec > 0;
        % We can reuse the ARRAY answer for it's children.
        set( node.getChildren, 'CanAdd', OK );
    case 'SSSTRUCT'
        newNumRec = size(node.LocalData.data, 1);
        OK = numRec == 0 || numRec == newNumRec;        
    case {'STRUCTARRAY'}
        children = node.getChildren;
        childOK = false(1,length(children));
        childNumRec = zeros(1,length(children));
        % Iterate over each child
        for i=1:length(childOK)
            % Ask the child
            [childOK(i), childNumRec(i)] = canAddData( children(i), ss, numRec );
        end
        OK = ~isempty(childOK) && all(childOK) && all(childNumRec == childNumRec(1));
        if OK
            newNumRec = childNumRec(1);
        end
    case 'CELL'
        children = node.getChildren;
        childOK = false(1,length(children));
        childNumRec = zeros(1,length(children));
        % Iterate over each child
        for i=1:length(childOK)
            % Ask the child
            [childOK(i), childNumRec(i)] = canAddData( children(i), ss, numRec);
        end
        OK= ~isempty(childOK) && all(childOK) && all(childNumRec == childNumRec(1));
        if OK
            newNumRec = childNumRec(1);
        end
    case 'TABLE'
        try
            % try to convert data to a double
            fIsConvertable = @(d) size(d,2)==1 && (isnumeric(d) || islogical(d) || iscategorical(d));
            isNumber = varfun(fIsConvertable,node.LocalData,'Output','uniform');
            newNumRec = size(node.LocalData, 1);
            OK = (numRec == 0 || numRec == newNumRec) && any(isNumber);
        catch
            OK = false;
        end
    case 'UNKNOWN'
        OK = false;
        newNumRec = -1;        
end

% set the add status for this node
node.CanAdd = OK;