This is a static copy of a profile report

Home

rmfield (Calls: 20, Time: 0.005 s)
Generated 16-Jul-2020 17:09:28 using performance time.
function in file /Applications/MATLAB_R2020a.app/toolbox/matlab/datatypes/rmfield.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
...tChanges>localUpdateColorsIfNeededsubfunction10
...tChanges>localUpdateSelectionStatesubfunction10
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
79
s = cell2struct(reshape(c(~toR...
200.002 s39.2%
45
toRemove = strcmp(deblank(fiel...
200.001 s13.1%
70
c = struct2cell(s);
200.001 s10.0%
40
f = fieldnames(s);
200.000 s8.0%
42
if ischar(field) || isscalar(f...
200.000 s5.3%
All other lines  0.001 s24.4%
Totals  0.005 s100% 
Children (called functions)
No children
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function81
Non-code lines (comments, blank lines)42
Code lines (lines that can run)39
Code lines that did run23
Code lines that did not run16
Coverage (did run/can run)58.97 %
Function listing
time 
Calls 
 line
   1 
function s = rmfield(s,field)
   2 
%RMFIELD Remove fields from a structure array.
   3 
%   S = RMFIELD(S,FIELD) removes the field specified by FIELD from the 
   4 
%   m x n structure array S. For example, S = RMFIELD(S,'a') removes the field
   5 
%   'a' from S. The size of input S is preserved.
   6 
%
   7 
%   S = RMFIELD(S,FIELDS) removes more than one field at a time when FIELDS
   8 
%   is a string, character array or cell array of character vectors. The
   9 
%   changed structure is returned. The size of input S is preserved.
  10 
%
  11 
%   See also SETFIELD, GETFIELD, ISFIELD, FIELDNAMES.
  12 

  13 
%   Copyright 1984-2017 The MathWorks, Inc.
  14 

  15 
%--------------------------------------------------------------------------------------------
  16 
% handle input arguments
  17 

  18 

< 0.001 
     20 
  19
if ~isa(s,'struct') 
  20 
    error(message('MATLAB:rmfield:Arg1NotStructArray'));
< 0.001 
     20 
  21
end 
  22 

< 0.001 
     20 
  23
field = convertStringsToChars(field); 
  24 

< 0.001 
     20 
  25
if iscell(field) && isempty(field) 
  26 
    % No fields to remove
  27 
    return
< 0.001 
     20 
  28
end 
  29 

< 0.001 
     20 
  30
if ~ischar(field) && ~iscellstr(field) 
  31 
    error(message('MATLAB:rmfield:FieldnamesNotStrings'));
< 0.001 
     20 
  32
end 
  33 

< 0.001 
     20 
  34
if ischar(field) && ~isrow(field) 
  35 
    % converts char matrix to cell-str but leave char vector alone
  36 
    field = cellstr(field);
< 0.001 
     20 
  37
end 
  38 

  39 
% get fieldnames of struct
< 0.001 
     20 
  40
f = fieldnames(s); 
  41 
% Determine which fieldnames to delete.
< 0.001 
     20 
  42
if ischar(field) || isscalar(field) 
  43 
    % shortcut for single field.
< 0.001 
     20 
  44
    nonexistent = []; 
< 0.001 
     20 
  45
    toRemove = strcmp(deblank(field),f); 
< 0.001 
     20 
  46
    if ~any(toRemove) 
  47 
        nonexistent = find(~toRemove,1);
< 0.001 
     20 
  48
    end 
  49 
elseif numel(f) < 100 && numel(field) < 10
  50 
    % faster for small number of fields
  51 
    [toRemove,nonexistent] = smallcase(f,field);
  52 
else
  53 
    % faster for large number of fields.
  54 
    [toRemove,nonexistent] = generalcase(f,field);
< 0.001 
     20 
  55
end 
  56 

  57 
% If any given fields were not found, throw an error
< 0.001 
     20 
  58
if ~isempty(nonexistent) 
  59 
    field = cellstr(field);
  60 
    name = field{nonexistent};
  61 
    % Make sure the given non-existent field name does not exceed max length
  62 
    if length(name) > namelengthmax
  63 
        error(message('MATLAB:rmfield:FieldnameTooLong', name));
  64 
    else
  65 
        error(message('MATLAB:rmfield:InvalidFieldname', name));
  66 
    end
< 0.001 
     20 
  67
end 
  68 

  69 
% convert struct to cell array
< 0.001 
     20 
  70
c = struct2cell(s); 
  71 

  72 
% find size of cell array
< 0.001 
     20 
  73
sz = size(c); 
  74 

  75 
% adjust size for fields to be removed
< 0.001 
     20 
  76
sz(1) = sz(1) - nnz(toRemove); 
  77 

  78 
% rebuild struct
  0.002 
     20 
  79
s = cell2struct(reshape(c(~toRemove,:),sz),f(~toRemove)); 
  80 
%--------------------------------------------------------------------------------------------
< 0.001 
     20 
  81
end 

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