gusucode.com > bigdata 工具箱 matlab源码程序 > bigdata/@tall/private/makeDummyTable.m
function [dummyT, knownClasses] = makeDummyTable(tw, fname) % makeDummyTable creates a table prototype from a table or tall table. % Copyright 2016 The MathWorks, Inc. if istall(tw) % This function create a table from a tall table adaptor. inVarNames = tw.Adaptor.VariableNames; adaptors = tw.Adaptor.VariableAdaptors; % Get Class from adaptors into function handles classes = cellfun(@(x)x.Class, adaptors, 'UniformOutput', false); if any(strcmp(classes, 'table')) error(message('MATLAB:bigdata:array:TableinTableNotSupported',upper(fname))); end % Check if class info are complete. knownClasses = ~any(strcmp(classes, '')); else inVarNames = tw.Properties.VariableNames; classes = varfun(@class, tw, 'OutputFormat', 'cell'); knownClasses = true; end % Construct dummy scalar variables outCell = cellfun(@(x)getScalar(x), classes, 'UniformOutput', false); % Create dummy table dummyT = table.fromScalarStruct(cell2struct(outCell,inVarNames,2)); dummyT.Properties.RowNames = {'first'}; end function y = getScalar(x) % getScalar create a scalar variable from class name. % getScalar must always return the same scalar for each class. % Otherwise, the subsequent table operations, like JOIN, will fail % when the scalar is used as a key variable. if isempty(x) % variable class not known. Treat it as double. y = 1; elseif strcmp(x,'cell') % Use cellstr in case this variable is used as keys. y = {char(1)}; elseif strcmp(x,'datetime') % datetime() is equal to datetime('now'), so we need this special case. y = datetime(1,1,1); else f = str2func(x); try y = f(1); % numeric, char, logical, categorical. catch y = f(); % duration, calendarDuration. end assert(isscalar(y)); end end