www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mbctree/@wksptreenode/createChildren.m
function createChildren(node, data, tree) %CREATECHILDREN Create children of the node % % CREATECHILDREN(NODE, DATA, TREE) % Copyright 2006-2015 The MathWorks, Inc. switch node.Type case {'SSSTRUCT','VECTOR', 'UNKNOWN'} % nothing case 'ARRAY' if size(data,2)<=10 % Iterate over the columns of the array for i = 1:size(data, 2) % Fill that node with the right stuff childName = sprintf( '%s%d', i_getNamePrefix(node), i ); child = i_makeNode( tree, childName, data(:, i), i ); child.LocalData = data(:, i); if ~isempty(child.getChildren) || child.canAddData node.add( child ); end end end case 'STRUCT' % Get the field in the structure fields = fieldnames(data); % Iterate over each element and create it for i = 1:length(fields) % Fill that node with the right stuff childName = sprintf( '%s%s', i_getNamePrefix(node), fields{i} ); child = i_makeNode( tree, childName, data.(fields{i}), i ); % Add the local data to the child child.LocalData = data.(fields{i}); if ~isempty(child.getChildren) || child.canAddData node.add( child ); end end case 'STRUCTARRAY' % Iterate over each element and create it for i = 1:length(data) % Fill that node with the right stuff childName = sprintf( '%s%d', i_getNamePrefix(node), i ); child = i_makeNode( tree, childName, data(i), i ); % Add the local data to the child child.LocalData = data(i); if ~isempty(child.getChildren) || child.canAddData node.add( child ); end end case 'CELL' for i = 1:numel(data) % Fill that node with the right stuff childName = sprintf( '%s%d', i_getNamePrefix(node), i ); child = i_makeNode(tree, childName, data{i}, i); % Add the local data to the child child.LocalData = data{i}; if ~isempty(child.getChildren) || child.canAddData node.add( child ); end end end %------------------------------------------------------------------------ function name = i_getNamePrefix(node) if isempty(node.VarName) name = ''; else name = [node.VarName '_']; end %------------------------------------------------------------------------ function node = i_makeNode( tree, name, data, index ) d = xregGui.uddDispatcher; node = d.feval( @mbctree.wksptreenode, tree, name, data, index );