This is a static copy of a profile report

Home

DetectImportOptionsSpreadsheet>DetectImportOptionsSpreadsheet.getOptsFromSheet (Calls: 2, Time: 0.185 s)
Generated 04-Jun-2021 04:11:08 using performance time.
class method in file C:\Program Files\MATLAB\R2020b\toolbox\matlab\io\spreadsheet\+matlab\+io\+internal\+functions\DetectImportOptionsSpreadsheet.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
...etectImportOptionsSpreadsheet.executeclass method2
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
172
opts.VariableTypes = types;
20.035 s18.8%
174
opts.VariableNamesRange = varN...
20.034 s18.6%
76
[types, metaRows] = matlab.io....
20.013 s7.1%
169
opts = matlab.io.spreadsheet.S...
20.013 s7.0%
180
names(specifiedNames) = matlab...
20.012 s6.5%
All other lines  0.078 s42.0%
Totals  0.185 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
...ns>ImportOptions.set.VariableTypesclass method20.034 s18.4%
...eadsheetInputs.set.VariableNamesRangeclass method20.034 s18.2%
detectTypesfunction20.012 s6.6%
...mportOptions.SpreadsheetImportOptionsclass method20.012 s6.6%
makeValidNamefunction20.012 s6.3%
readSpreadsheetVariablefunction20.009 s5.0%
...ts>SpreadsheetInputs.set.DataRangeclass method20.008 s4.2%
...portOptions.TextVariableImportOptionsclass method20.007 s3.6%
...t;SpreadsheetInputs.set.RowNamesRangeclass method20.007 s3.5%
...rtOptionsSpreadsheet>getHeaderRowsclass method20.005 s2.7%
...gt;AcceptsSheetNameOrNumber.set.Sheetclass method20.004 s2.3%
makeUniqueStringsfunction20.004 s2.2%
...rtOptions>ImportOptions.setvartypeclass method20.004 s2.1%
...;DetectImportOptions.setVariablePropsclass method20.003 s1.5%
...ionsSpreadsheet.getRangeFromUsedRangeclass method20.002 s1.0%
...portOptionsSpreadsheet>getCellNameclass method40.001 s0.8%
...eNamesInput.set.PreserveVariableNamesclass method20.001 s0.7%
...etaDataFromDetection.setMetaLocationsclass method20.001 s0.7%
...etectImportOptions.set.NumHeaderLinesclass method20.001 s0.5%
...gt;AcceptsSheetNameOrNumber.get.Sheetclass method20.001 s0.3%
VarOptsInputs>VarOptsInputs.get.Typeclass method20.001 s0.3%
FastVarOpts>FastVarOpts.setVarNamesclass method20.000 s0.2%
...ImportOptionsSpreadsheet.setFilePropsclass method20.000 s0.2%
...eNamesInput.get.PreserveVariableNamesclass method40.000 s0.2%
columnLetterfunction10.000 s0.0%
Self time (built-ins, overhead, etc.)  0.022 s11.8%
Totals  0.185 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function155
Non-code lines (comments, blank lines)35
Code lines (lines that can run)120
Code lines that did run71
Code lines that did not run49
Coverage (did run/can run)59.17 %
Function listing
time 
Calls 
 line
  43 
        function [opts,func] = getOptsFromSheet(func,supplied)
  44 
            import matlab.io.spreadsheet.internal.*;
< 0.001 
      2 
  45
            sheet = func.WorkSheet.SheetObj; 
< 0.001 
      2 
  46
            if supplied.DataRange 
  47 
                func.Range = func.DataRange;
< 0.001 
      2 
  48
            end 
  49 
            
< 0.001 
      2 
  50
            if (supplied.Range||supplied.DataRange) && ~isempty(func.Range) 
  51 
                [rangeToUse,bindRanges,rangeStr,typeIDs] = func.getRangeFromSheet(supplied);
< 0.001 
      2 
  52
            else 
  0.002 
      2 
  53
                [rangeToUse,bindRanges,rangeStr,typeIDs] = func.getRangeFromUsedRange(); 
< 0.001 
      2 
  54
            end 
  55 
            
< 0.001 
      2 
  56
            if isempty(rangeToUse) || all(typeIDs(:) == sheet.BLANK | typeIDs(:) == sheet.EMPTY | typeIDs(:) == sheet.ERROR) 
  57 
 
  58 
                opts = matlab.io.spreadsheet.SpreadsheetImportOptions('NumVariables',size(typeIDs,2),'Sheet',func.Sheet);
  59 
                if func.PreserveRange
  60 
                    opts.DataRange = rangeStr;
  61 
                    opts = setvartype(opts,func.EmptyColumnType);
  62 
                end
  63 
                opts = func.setFileProps(supplied,opts);
  64 
                return;
< 0.001 
      2 
  65
            end 
  66 
            
  67 
            % find header rows/cols
< 0.001 
      2 
  68
            if ~supplied.NumHeaderLines && ~func.PreserveRange 
  0.007 
      2 
  69
                func.NumHeaderLines = getHeaderRows(typeIDs); 
  70 
            elseif ischar(func.NumHeaderLines) && func.NumHeaderLines == "auto"
  71 
                func.NumHeaderLines = 0;
< 0.001 
      2 
  72
            end 
< 0.001 
      2 
  73
            headerRows = func.NumHeaderLines; 
  74 
            
  75 
            % detect types
  0.013 
      2 
  76
            [types, metaRows] = matlab.io.spreadsheet.internal.detectTypes(typeIDs(headerRows+1:end,:),func.EmptyColumnType,[],func.ReadVariableNames); 
  77 
            
  0.002 
      2 
  78
            meta = func.setMetaLocations(supplied, metaRows); 
  79 

< 0.001 
      2 
  80
            if ~supplied.VariableNamesRange 
< 0.001 
      2 
  81
                if meta.VarNames 
  82 
                    % get the row range used to read var names
< 0.001 
      2 
  83
                    varNameRange = [rangeToUse(1) + headerRows, rangeToUse(2), 1, numel(types)]; 
  84 
                    
  85 
                    % read the variables, converting any names
  0.007 
      2 
  86
                    tvio = matlab.io.TextVariableImportOptions(); 
  0.011 
      2 
  87
                    names = matlab.io.spreadsheet.internal.readSpreadsheetVariable(tvio.Type,tvio,sheet,varNameRange,typeIDs(headerRows+1,:)); 
  88 
                else
  89 
                    % Var1, Var2, ... , VarN
  90 
                    names = strings(1,size(typeIDs,2));
  91 
                    if meta.RowNames
  92 
                        names(1) = "Row";
  93 
                    end
  94 
                    names = cellstr(names);
< 0.001 
      2 
  95
                end 
  96 
            else
  97 
                tvio = matlab.io.TextVariableImportOptions();
  98 
                [varRangeToUse,bindRanges] = getRangeInfo(sheet,func.VariableNamesRange);
  99 
                if ~bindRanges(2)
 100 
                    varRangeToUse(4) = rangeToUse(4);
 101 
                end
 102 
                [varRangeToUse,~,varTypeIDs] = getEffectiveRange(func.WorkSheet,varRangeToUse,supplied.Range,true);
 103 
                varTypeIDs(:) = sheet.STRING;
 104 
                names = matlab.io.spreadsheet.internal.readSpreadsheetVariable(tvio.Type,tvio,sheet,varRangeToUse,varTypeIDs);
< 0.001 
      2 
 105
            end 
 106 
            
< 0.001 
      2 
 107
            if ~func.DetectMetaLines 
 108 
                metaRows = 0;
< 0.001 
      2 
 109
            end 
 110 

< 0.001 
      2 
 111
            startRow = rangeToUse(1) + headerRows + metaRows; 
< 0.001 
      2 
 112
            startCol = rangeToUse(2) + meta.RowNames; 
  0.002 
      2 
 113
            dataRange = getCellName(startRow, startCol); 
< 0.001 
      2 
 114
            if bindRanges(1) 
 115 
                if numel(names) - meta.RowNames > 0
 116 
                    % only try setting a bound range if there 
 117 
                    % is at least 1 variable
 118 
                    if contains(rangeStr,':')
 119 
                        rangeStr = strsplit(rangeStr,':');
 120 
                        dataRange = strjoin({dataRange,rangeStr{2}},':');
 121 
                    else
 122 
                        dataRange = [dataRange ':' dataRange];
 123 
                    end
 124 
                end
< 0.001 
      2 
 125
            end 
 126 

< 0.001 
      2 
 127
            if meta.RowNames 
< 0.001 
      1 
 128
                L = columnLetter(rangeToUse(2)); 
< 0.001 
      1 
 129
                rowNamesRange = L+":"+L; 
< 0.001 
      1 
 130
                names(1) = []; 
< 0.001 
      1 
 131
                types(1) = []; 
< 0.001 
      1 
 132
            else 
< 0.001 
      1 
 133
                rowNamesRange = ''; 
      2 
 134
            end 
 135 
            
< 0.001 
      2 
 136
            if meta.VarNames 
< 0.001 
      2 
 137
                varNamesRow = rangeToUse(1) + headerRows; 
< 0.001 
      2 
 138
                startCol = rangeToUse(2) + meta.RowNames; 
< 0.001 
      2 
 139
                varNameRange = getCellName(varNamesRow, startCol); 
< 0.001 
      2 
 140
                if bindRanges(2) 
 141 
                    if numel(names) > 0
 142 
                        % Only set VariableNamesRange to a bound
 143 
                        % rectangular range if there is at least 1 Variable
 144 
                        endCol = startCol + numel(names) - 1;
 145 
                        varNameRange = strjoin({varNameRange, getCellName(varNamesRow, endCol)}, ':');
 146 
                    else
 147 
                        % there are zero variables so VariableNamesRange 
 148 
                        % can't be set to a bound rectangular range
 149 
                        varNameRange = '';
 150 
                    end
< 0.001 
      2 
 151
                end 
 152 
            else
 153 
                varNameRange = '';
< 0.001 
      2 
 154
            end 
 155 
            
< 0.001 
      2 
 156
            if supplied.ExpectedNumVariables 
 157 
                numVars = min([numel(names),func.ExpectedNumVariables]);
 158 
                names = names(1:numVars);
 159 
                types = types(1:numVars);
< 0.001 
      2 
 160
            end 
 161 
            
< 0.001 
      2 
 162
            if numel(names) < numel(types) 
 163 
                idx = numel(names)+1:numel(types);
 164 
                names(idx) = {''};
< 0.001 
      2 
 165
            elseif numel(names) >  numel(types) 
 166 
                names(numel(types)+1:end) = [];
< 0.001 
      2 
 167
            end 
 168 

  0.013 
      2 
 169
            opts = matlab.io.spreadsheet.SpreadsheetImportOptions('NumVariables',numel(types)); 
 170 

  0.003 
      2 
 171
            opts.PreserveVariableNames = func.PreserveVariableNames; 
  0.035 
      2 
 172
            opts.VariableTypes = types; 
  0.005 
      2 
 173
            opts.Sheet = func.Sheet; 
  0.034 
      2 
 174
            opts.VariableNamesRange = varNameRange; 
 175 

< 0.001 
      2 
 176
            specifiedNames = (strlength(names)>0); 
 177 
            % Only normalize variable names if PreserveVariableNames is set
 178 
            % to false.
< 0.001 
      2 
 179
            if ~func.PreserveVariableNames 
  0.012 
      2 
 180
                names(specifiedNames) = matlab.lang.makeValidName(names(specifiedNames)); 
< 0.001 
      2 
 181
            end 
  0.005 
      2 
 182
            names(specifiedNames) = matlab.lang.makeUniqueStrings(names(specifiedNames),{},namelengthmax); 
 183 

  0.008 
      2 
 184
            opts.DataRange = dataRange; 
  0.007 
      2 
 185
            opts.RowNamesRange = rowNamesRange; 
< 0.001 
      2 
 186
            typeIDs(1:meta.DataRow-1,:) = []; 
< 0.001 
      2 
 187
            if meta.RowNames 
 188 
                % Remove the column associated with the RowNames from typeIDs
< 0.001 
      1 
 189
                typeIDs(:, 1) = []; 
< 0.001 
      2 
 190
            end 
 191 

< 0.001 
      2 
 192
            blanks = all(typeIDs == sheet.BLANK | typeIDs == sheet.EMPTY | typeIDs == sheet.ERROR,1); 
  0.005 
      2 
 193
            opts = opts.setvartype(blanks,func.EmptyColumnType); 
  0.001 
      2 
 194
            opts.fast_var_opts = opts.fast_var_opts.setVarNames(1:numel(names), names(:)); 
  0.003 
      2 
 195
            opts = func.setVariableProps(supplied,opts); 
  0.001 
      2 
 196
            opts = func.setFileProps(supplied,opts); 
< 0.001 
      2 
 197
        end 

Other subfunctions in this file are not included in this listing.