This is a static copy of a profile report

Home

cell.ismember (Calls: 2, Time: 0.012 s)
Generated 04-Jun-2021 04:11:21 using performance time.
function in file C:\Program Files\MATLAB\R2020b\toolbox\matlab\ops\@cell\ismember.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
readSpreadsheetfunction2
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
62
[uA,~,icA] = unique(a(:),'sort...
20.006 s52.6%
78
[lia,locb] = ismember(icA,indR...
20.003 s23.7%
66
[uB,ib] = unique(b(:),'sorted'...
20.001 s5.5%
33
if ~((ischar(a) || iscellstr(a...
20.000 s2.4%
71
d = strcmp(sortuAuB(1:end-1),s...
20.000 s2.4%
All other lines  0.002 s13.5%
Totals  0.012 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
cell.uniquefunction40.006 s49.4%
ismemberfunction20.003 s21.5%
Self time (built-ins, overhead, etc.)  0.003 s29.1%
Totals  0.012 s100% 
Code Analyzer results
Line numberMessage
33To support string in addition to cellstr, include a call to 'isstring'.
33To support string in addition to cellstr, include a call to 'isstring'.
Coverage results
Show coverage for parent directory
Total lines in function102
Non-code lines (comments, blank lines)39
Code lines (lines that can run)63
Code lines that did run33
Code lines that did not run30
Coverage (did run/can run)52.38 %
Function listing
time 
Calls 
 line
   1 
function [lia,locb] = ismember(a,b,flag1,flag2)
   2 
%ISMEMBER True for set member.
   3 
%   LIA = ISMEMBER(A,B) for cell arrays A and B returns an array of the same
   4 
%   size as A containing true where the elements of A are in B and false 
   5 
%   otherwise.
   6 
%
   7 
%   [LIA,LOCB] = ISMEMBER(A,B) also returns an array LOCB containing the
   8 
%   lowest absolute index in B for each element in A which is a member of 
   9 
%   B and 0 if there is no such index.
  10 
%
  11 
%   Inputs A and B must be strings or cell arrays of strings.
  12 
%
  13 
%     The behavior of ISMEMBER has changed.  This includes:
  14 
%       - occurrence of indices in LOCB switched from highest to lowest
  15 
%     If this change in behavior has adversely affected your code, you may 
  16 
%     preserve the previous behavior with:
  17 
%        [LIA,LOCB] = ISMEMBER(A,B,'legacy')
  18 
%
  19 
%   Example:
  20 
%
  21 
%      a = {'red','green'}
  22 
%      b = {'gray','blue','red','orange'}
  23 
%      [lia,locb] = ismember(a,b)
  24 
%
  25 
%      % returns  lia = [1 0]  and  locb = [3 0]
  26 
%
  27 
%   See also UNIQUE, UNION, INTERSECT, SETDIFF, SETXOR, SORT, SORTROWS.
  28 

  29 
%   Copyright 1984-2014 The MathWorks, Inc.
  30 

< 0.001 
      2 
  31
if nargin <= 2 
  32 
    % The only A and B allowed are character arrays or cellstr.
< 0.001 
      2 
  33
    if ~((ischar(a) || iscellstr(a)) && (ischar(b) || iscellstr(b))) 
  34 
        error(message('MATLAB:ISMEMBER:InputClass',class(a),class(b)));
< 0.001 
      2 
  35
    end 
  36 
    % Scalar A: no sort needed
< 0.001 
      2 
  37
    if (ischar(a) && isrow(a)) || isscalar(a) 
  38 
        match = strcmp(a,b);
  39 
        lia = any(match(:));
  40 
        if nargout > 1
  41 
            if lia
  42 
                locb = find(match,1,'first');
  43 
            else
  44 
                locb = 0;
  45 
            end
  46 
        end
  47 
    % Scalar B: no sort needed
< 0.001 
      2 
  48
    elseif (ischar(b) && isrow(b)) || isscalar(b) 
  49 
        lia = strcmp(a,b);
  50 
        if nargout > 1
  51 
            locb = double(lia);
  52 
        end
< 0.001 
      2 
  53
    else 
  54 
        % If A or B is char, convert it to a cellstr and remove trailing spaces
< 0.001 
      2 
  55
        if ischar(a) 
  56 
            a = cellstr(a);
< 0.001 
      2 
  57
        end 
< 0.001 
      2 
  58
        if ischar(b) 
  59 
            b = cellstr(b);
< 0.001 
      2 
  60
        end 
  61 
        % Duplicates within the sets are eliminated
  0.006 
      2 
  62
        [uA,~,icA] = unique(a(:),'sorted'); 
< 0.001 
      2 
  63
        if nargout <= 1 
  64 
            uB = unique(b(:),'sorted');
< 0.001 
      2 
  65
        else 
< 0.001 
      2 
  66
            [uB,ib] = unique(b(:),'sorted'); 
< 0.001 
      2 
  67
        end 
  68 
        % Sort the unique elements of A and B, duplicate entries are adjacent
< 0.001 
      2 
  69
        [sortuAuB,IndSortuAuB] = sort([uA;uB]); 
  70 
        % d indicates the indices matching entries
< 0.001 
      2 
  71
        d = strcmp(sortuAuB(1:end-1),sortuAuB(2:end)); 
< 0.001 
      2 
  72
        indReps = IndSortuAuB(d);                  % Find locations of repeats 
< 0.001 
      2 
  73
        if nargout <= 1 
  74 
            lia = ismember(icA,indReps);           % Find repeats among original list
< 0.001 
      2 
  75
        else 
< 0.001 
      2 
  76
            szuA = size(uA,1); 
< 0.001 
      2 
  77
            d = find(d); 
  0.003 
      2 
  78
            [lia,locb] = ismember(icA,indReps);    % Find locb by using given indices 
< 0.001 
      2 
  79
            newd = d(locb(lia));                   % NEWD is D for non-unique A 
< 0.001 
      2 
  80
            where = ib(IndSortuAuB(newd+1)-szuA); 
< 0.001 
      2 
  81
            locb(lia) = where; 
< 0.001 
      2 
  82
        end 
< 0.001 
      2 
  83
        lia = reshape(lia,size(a)); 
< 0.001 
      2 
  84
        if nargout > 1 
< 0.001 
      2 
  85
            locb = reshape(locb,size(a)); 
< 0.001 
      2 
  86
        end 
< 0.001 
      2 
  87
    end 
  88 
elseif nargin == 3
  89 
    % ISMEMBER(a,b,'legacy'), ISMEMBER(a,b,'R2012a')
  90 
    if nargout < 2
  91 
        lia = cellismemberlegacy(a,b,flag1);
  92 
    else
  93 
        [lia,locb] = cellismemberlegacy(a,b,flag1);
  94 
    end
  95 
else
  96 
    % ISMEMBER(a,b,'rows','legacy'), ISMEMBER(a,b,'rows','R2012a')
  97 
    if nargout < 2
  98 
        lia = cellismemberlegacy(a,b,flag1,flag2);
  99 
    else
 100 
        [lia,locb] = cellismemberlegacy(a,b,flag1,flag2);
 101 
    end
< 0.001 
      2 
 102
end 

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