This is a static copy of a profile report

Home

tabular.setProperty (Calls: 12, Time: 0.015 s)
Generated 04-Jun-2021 04:11:11 using performance time.
function in file C:\Program Files\MATLAB\R2020b\toolbox\matlab\datatypes\tabular\@tabular\setProperty.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
tabular.subsasgnDotfunction12
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
173
t.varDim = t.varDim.setUnits(p...
20.002 s11.8%
171
t.varDim = t.varDim.setDescrs(...
20.002 s11.1%
25
name = tabular.matchPropertyNa...
120.002 s10.8%
149
t.rowDim = t.rowDim.setLabels(...
60.001 s9.2%
160
t.varDim = t.varDim.setLabels(...
20.001 s8.2%
All other lines  0.007 s49.0%
Totals  0.015 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
...mension>tabularDimension.setLabelsclass method80.002 s11.4%
varNamesDim>varNamesDim.setUnitsclass method20.001 s8.5%
tabular.matchPropertyNamefunction120.001 s8.1%
varNamesDim>varNamesDim.setDescrsclass method20.001 s7.4%
tabular.getPropertyfunction20.001 s5.3%
isTextfunction20.000 s2.8%
metaDim>metaDim.checkAgainstVarLabelsclass method20.000 s1.7%
Self time (built-ins, overhead, etc.)  0.008 s54.8%
Totals  0.015 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function221
Non-code lines (comments, blank lines)80
Code lines (lines that can run)141
Code lines that did run51
Code lines that did not run90
Coverage (did run/can run)36.17 %
Function listing
time 
Calls 
 line
   1 
function t = setProperty(t,name,p)
   2 
%SETPROPERTY Set a table property.
   3 

   4 
%   Copyright 2012-2019 The MathWorks, Inc.
   5 

   6 
% We may be given a name (when called from set), or a subscript expression
   7 
% that starts with a '.name' subscript (when called from subsasgn).  Get the
   8 
% name and validate it in any case.
   9 

  10 
import matlab.tabular.Continuity
  11 
import matlab.internal.datatypes.defaultarrayLike
  12 

< 0.001 
     12 
  13
if isstruct(name) 
< 0.001 
     12 
  14
    s = name; 
< 0.001 
     12 
  15
    if s(1).type ~= '.' 
  16 
        error(message('MATLAB:table:InvalidSubscript'));
< 0.001 
     12 
  17
    end 
< 0.001 
     12 
  18
    name = s(1).subs; 
< 0.001 
     12 
  19
    haveSubscript = true; 
  20 
else
  21 
    haveSubscript = false;
< 0.001 
     12 
  22
end 
  23 
% Allow partial match for property names if this is via the set method;
  24 
% require exact match if it is direct assignment via subsasgn
  0.002 
     12 
  25
name = tabular.matchPropertyName(name,t.propertyNames,haveSubscript); 
  26 

< 0.001 
     12 
  27
if haveSubscript && ~isscalar(s) 
  28 
    % If this is 1-D named parens/braces subscripting, convert labels to 
  29 
    % correct indices for properties that support subscripting with labels. 
  30 
    % e.g. t.Properties.RowNames('SomeRowName')
< 0.001 
      2 
  31
    if (s(2).type ~= ".") && isscalar(s(2).subs) 
< 0.001 
      2 
  32
        sub = s(2).subs{1}; 
< 0.001 
      2 
  33
        if matlab.internal.datatypes.isText(sub) % a name, names, or colon 
  34 
            switch name
  35 
            case {'VariableNames' 'VariableDescriptions' 'VariableUnits' 'VariableContinuity'}
  36 
                s(2).subs{1} = t.varDim.subs2inds(sub);
  37 
            case {'RowNames' 'RowTimes'}
  38 
                s(2).subs{1} = t.rowDim.subs2inds(sub);
  39 
            case 'DimensionNames'
  40 
                s(2).subs{1} = t.metaDim.subs2inds(sub); 
  41 
            case  'CustomProperties' % Error for any non-dot subscript below t.Properties.CustomProperties
  42 
                error(message('MATLAB:table:InvalidSubscript'))
  43 
            end
< 0.001 
      2 
  44
        end 
< 0.001 
      2 
  45
    end 
  46 
    
< 0.001 
      2 
  47
    if name == "CustomProperties" 
  48 
        % Because CustomProperties can be either per-variable or per-table, they
  49 
        % need to be handled separately. Avoid getProperty and constructing the
  50 
        % object. Instead, work directly on the custom props structs.
  51 
        if isfield(t.varDim.customProps,s(2).subs) % per-variable
  52 
            % We don't allow tables as per-variable properties so the
  53 
            % subsasgnRecursor isn't necessary.
  54 
            isPerVar = true;
  55 
            LHScell = { t.varDim.customProps };
  56 
            s(1).type = '{}'; s(1).subs = {1};
  57 
            % Support assignment to a single variable
  58 
            % (t.Properties.CustomProperties.prop(3) = x), by first filling the
  59 
            % variables with default of the right type and to ensure that
  60 
            % the properties are the same length as the width of the table.
  61 
            if numel(s) > 2
  62 
                % Support named subscript in () or {} on per-variable.
  63 
                s(3).subs{1} = t.varDim.subs2inds(s(3).subs{1});
  64 
                if isequal(size(subsref(LHScell,s(1:2))),[0,0])
  65 
                    % Support assigning to a particular element of a previously empty custom property. e.g. t.Properties.CustomProperties.Foo{3} = 'abc'
  66 
                    if s(3).type == "()"
  67 
                        LHScell = builtin('subsasgn',LHScell,s(1:2), defaultarrayLike(size(t.varDim.labels), 'like', p, false));
  68 
                    elseif s(3).type == "{}"
  69 
                        LHScell = builtin('subsasgn',LHScell,s(1:2), defaultarrayLike(size(t.varDim.labels), 'like', {p}, false));
  70 
                    end
  71 
                end
  72 
            end
  73 
            LHScell = builtin('subsasgn',LHScell,s,p);
  74 
        elseif isfield(t.arrayProps.TableCustomProperties,s(2).subs) % per-table
  75 
            isPerVar = false;
  76 
            LHScell = { t.arrayProps.TableCustomProperties };
  77 
            s(1).type = '{}'; s(1).subs = {1};
  78 
            % Per-table CustomProperties may be a table, so need
  79 
            % subsasgnRecursor to break the chain.
  80 
            LHScell = matlab.internal.tabular.private.subsasgnRecurser(LHScell,s,p);
  81 
        else
  82 
            error(message('MATLAB:table:InvalidCustomPropName'))
  83 
        end
< 0.001 
      2 
  84
    else 
  85 
        % If there's cascaded subscripting into the property, get the existing
  86 
        % property value and let the property's subsasgn handle the assignment.
  87 
        % The property may currently be empty, ask for a non-empty default
  88 
        % version to allow assignment into only some elements. Guarantee correct
  89 
        % dispatch for the assignment by working inside a scalar cell and letting
  90 
        % built-in cell subscripting dispatch.
  0.001 
      2 
  91
        LHScell = { t.getProperty(name,true) }; 
  92 

< 0.001 
      2 
  93
        s(1).type = '{}'; s(1).subs = {1}; 
  94 

< 0.001 
      2 
  95
        if name == "UserData" 
  96 
            LHScell = matlab.internal.tabular.private.subsasgnRecurser(LHScell,s,p);
< 0.001 
      2 
  97
        else 
  98 
            % We want to catch assigning '' into the variable properties using parens
  99 
            % to throw a better error message. Assigning '' into an array means
 100 
            % deletion, but it most likely wasn't the user's intention for these
 101 
            % properties - they probably wanted to assign empty. Deleting a single
 102 
            % value from variable properties is not a possible operation since the
 103 
            % number of variable properties must match the number of variables. Thus,
 104 
            % an error will be thrown for incorrect number of continuity later on,
 105 
            % which will be confusing. Throw a better error here instead.
< 0.001 
      2 
 106
            if ~isstring(p) && isequal(p,'') && (s(2).type == "()") 
 107 
                if matches(name, ["VariableNames" "VariableDescriptions" "VariableUnits"])
 108 
                    error(message('MATLAB:invalidConversion','cell','char'));
 109 
                elseif name == "VariableContinuity"
 110 
                    error(message('MATLAB:table:InvalidContinuityValue'));
 111 
                end           
< 0.001 
      2 
 112
            end 
 113 

 114 
            % Okay to convert strings because UserData and CustomProperties do
 115 
            % not go through here.
< 0.001 
      2 
 116
            if isstring(p) 
 117 
                p = cellstr(p);
< 0.001 
      2 
 118
            end 
 119 

< 0.001 
      2 
 120
            try  
< 0.001 
      2 
 121
                LHScell = builtin('subsasgn',LHScell,s,p); 
 122 
            catch ME 
 123 
                if ME.identifier == "MATLAB:UnableToConvert" && name == "VariableContinuity"
 124 
                    % Need to check for invalid enum value, for better error message. 
 125 
                    error(message('MATLAB:table:InvalidContinuityValue'));
 126 
                else
 127 
                    rethrow(ME);
 128 
                end
< 0.001 
      2 
 129
            end    
< 0.001 
      2 
 130
        end 
< 0.001 
      2 
 131
    end 
< 0.001 
      2 
 132
    p = LHScell{1}; 
 133 
    % The assignment may change the property's shape or size or otherwise make
 134 
    % it invalid; that gets checked by the individual setproperty methods called
 135 
    % below.
< 0.001 
     10 
 136
else 
 137 
    % If we are not assigning into property, we want to error in one specific
 138 
    % case, when the assignment is for the whole VariableContinuity property
 139 
    % and the value being assigned is character vector.
< 0.001 
     10 
 140
    if ischar(p) && name == "VariableContinuity" 
 141 
        error(message('MATLAB:table:InvalidContinuityFullAssignment')); 
< 0.001 
     10 
 142
    end 
< 0.001 
     12 
 143
end 
 144 

 145 
% Assign the new property value into the dataset.
< 0.001 
     12 
 146
try 
< 0.001 
     12 
 147
    switch name 
< 0.001 
     12 
 148
        case {'RowNames' 'RowTimes'} 
  0.001 
      6 
 149
            t.rowDim = t.rowDim.setLabels(p); % error if duplicate, or empty 
 150 
        
 151 
        % These three have already been verified present by matchPropertyName
< 0.001 
      6 
 152
        case 'StartTime' 
 153 
            t.rowDim = t.rowDim.setStartTime(p);
< 0.001 
      6 
 154
        case 'TimeStep' 
 155 
            t.rowDim = t.rowDim.setTimeStep(p);
< 0.001 
      6 
 156
        case 'SampleRate' 
 157 
            t.rowDim = t.rowDim.setSampleRate(p);
 158 
        
< 0.001 
      6 
 159
        case 'VariableNames' 
  0.001 
      2 
 160
            t.varDim = t.varDim.setLabels(p); % error if invalid, duplicate, or empty 
 161 
            % Check for conflicts between the new VariableNames and the existing
 162 
            % DimensionNames. For backwards compatibility, a table will modify
 163 
            % DimensionNames and warn, while a timetable will error.
< 0.001 
      2 
 164
            t.metaDim = t.metaDim.checkAgainstVarLabels(t.varDim.labels); 
< 0.001 
      4 
 165
        case 'DimensionNames' 
 166 
            t.metaDim = t.metaDim.setLabels(p); % error if duplicate, or empty
 167 
            % Check for conflicts between the new DimensionNames and the existing
 168 
            % VariableNames.
 169 
            t.metaDim = t.metaDim.checkAgainstVarLabels(t.varDim.labels);
< 0.001 
      4 
 170
        case 'VariableDescriptions' 
  0.002 
      2 
 171
            t.varDim = t.varDim.setDescrs(p); 
< 0.001 
      2 
 172
        case 'VariableUnits' 
  0.002 
      2 
 173
            t.varDim = t.varDim.setUnits(p); 
 174 
        case 'VariableContinuity'
 175 
            % Assigning single character vector to whole VariableContinuity property
 176 
            % should already be caught above.
 177 
            t.varDim = t.varDim.setContinuity(p);
 178 
        case 'Description'
 179 
            t = t.setDescription(p);
 180 
        case 'UserData'
 181 
            t = t.setUserData(p);
 182 
        case 'CustomProperties'
 183 
            if ~haveSubscript || isscalar(s)
 184 
                if isa(p,'matlab.tabular.CustomProperties')
 185 
                    % t.Properties.CustomProperties = p
 186 
                    % Assign CustomProperties object back into table.
 187 
                    [vnames, tnames] = getNames(p);
 188 
                    % First clear custom properties
 189 
                    t.varDim = t.varDim.setCustomProps(struct);
 190 
                    t.arrayProps.TableCustomProperties = struct;
 191 
                    for ii = 1:numel(vnames)
 192 
                        t.varDim = t.varDim.setCustomProp(p.(vnames{ii}),vnames{ii});
 193 
                    end
 194 
                    for ii = 1:numel(tnames)
 195 
                        t = t.setPerTableProperty(p.(tnames{ii}),tnames{ii});
 196 
                    end
 197 
                else
 198 
                    error(message('MATLAB:table:InvalidCustomPropertiesAssignment'))
 199 
                end
 200 
            else
 201 
                % Deeper assignment to a particular custom property. The
 202 
                % subscripted assignment was already done above, and it was
 203 
                % determined whether it is per-var or per-table, so just do
 204 
                % the assignment here.
 205 
                propName = s(2).subs;
 206 
                if isPerVar
 207 
                    t.varDim = t.varDim.setCustomProp(p.(propName), propName);
 208 
                else % isPerTable
 209 
                    t = t.setPerTableProperty(p.(propName), propName);
 210 
                end
 211 
            end
< 0.001 
     12 
 212
    end 
 213 
catch ME
 214 
    % Distinguish between full-assignment and partial assignment of variable
 215 
    % names and throw different messages.
 216 
    if ME.identifier == "MATLAB:table:InvalidVarNames" && (haveSubscript && ~isscalar(s)) && (s(2).type == "{}")
 217 
        error(message('MATLAB:table:InvalidVarNameBraces'));
 218 
    else
 219 
        rethrow(ME)
 220 
    end
< 0.001 
     12 
 221
end 

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