time | Calls | line |
---|
| | 85 | function t = buildTableFromData(data, varNames, rowNames, dimNames, readVarNames, readRowNames, preserveVariableNames)
|
| | 86 |
|
| | 87 | % Change variable name validation and fixing behavior based on the value
|
| | 88 | % of PreserveVariableNames.
|
< 0.001 | 2 | 89 | if preserveVariableNames
|
| | 90 | variableNameBehavior = 'warnSaved';
|
< 0.001 | 2 | 91 | else
|
| | 92 | % The legacy behavior is to normalize to valid MATLAB identifiers.
|
< 0.001 | 2 | 93 | variableNameBehavior = 'warnSavedLegacy';
|
< 0.001 | 2 | 94 | end
|
| | 95 |
|
| | 96 | % Set the var names. These will be modified to make them valid, and the
|
| | 97 | % original strings saved in the VariableDescriptions property. Fix up duplicate
|
| | 98 | % or empty names.
|
0.006 | 2 | 99 | validNames = matlab.internal.tabular.private.varNamesDim.makeValidName(varNames, variableNameBehavior);
|
< 0.001 | 2 | 100 | dimNames = matlab.lang.makeValidName(dimNames);
|
| | 101 |
|
< 0.001 | 2 | 102 | if readVarNames
|
< 0.001 | 2 | 103 | validNames = matlab.lang.makeUniqueStrings(validNames,{},namelengthmax);
|
< 0.001 | 2 | 104 | reservedNames = [validNames(:); dimNames{1}];
|
< 0.001 | 2 | 105 | if any(strcmp(dimNames{2},reservedNames))
|
| | 106 | % Make sure var names and dim names don't conflict. That could happen if var
|
| | 107 | % names read from the file are the same as the default dim names (when ReadRowNames
|
| | 108 | % is false), or same as the first dim name read from the file (ReadRowNames true).
|
| | 109 | dimNames{2} = matlab.lang.makeUniqueStrings(dimNames{2},reservedNames,namelengthmax);
|
< 0.001 | 2 | 110 | end
|
| | 111 | else
|
| | 112 | dimNames{2} = 'Variables';
|
< 0.001 | 2 | 113 | end
|
| | 114 |
|
< 0.001 | 2 | 115 | if readRowNames
|
0.002 | 1 | 116 | rowNames = matlab.internal.tabular.private.rowNamesDim.makeValidName(rowNames, 'silent');
|
< 0.001 | 2 | 117 | end
|
| | 118 |
|
| | 119 | % make dimNames and validNames unqiue
|
< 0.001 | 2 | 120 | dimnames = convertCharsToStrings(dimNames);
|
< 0.001 | 2 | 121 | validnames = convertCharsToStrings(validNames);
|
< 0.001 | 2 | 122 | if any(dimnames(:)' == validnames(:), 'all')
|
| | 123 | dimNames = matlab.lang.makeUniqueStrings(dimNames,validNames,namelengthmax);
|
< 0.001 | 2 | 124 | end
|
| | 125 |
|
< 0.001 | 2 | 126 | numVars = numel(data);
|
< 0.001 | 2 | 127 | if numVars > 0
|
< 0.001 | 2 | 128 | numRows = size(data{1}, 1);
|
| | 129 | else
|
| | 130 | numRows = numel(rowNames);
|
< 0.001 | 2 | 131 | end
|
0.031 | 2 | 132 | t = table.init(data,numRows,rowNames,numVars,validNames,dimNames);
|
< 0.001 | 2 | 133 | if numVars > 0 && any(~strcmp(validNames,varNames))
|
0.011 | 2 | 134 | t.Properties.VariableDescriptions = varNames;
|
< 0.001 | 2 | 135 | end
|
< 0.001 | 2 | 136 | end
|
Other subfunctions in this file are not included in this listing.