This is a static copy of a profile report

Home

cell.ismember (Calls: 94, Time: 0.006 s)
Generated 16-Jul-2020 17:09:07 using performance time.
function in file /Applications/MATLAB_R2020a.app/toolbox/matlab/ops/@cell/ismember.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
legend>process_inputssubfunction8
Legend.doUpdatefunction22
Legend.doMethod>createEntriessubfunction56
Legend.doMethod>printcallbacksubfunction8
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
37
if (ischar(a) && isrow...
940.002 s36.3%
33
if ~((ischar(a) || iscellstr(a...
940.002 s26.4%
38
match = strcmp(a,b);
940.000 s5.0%
39
lia = any(match(:));
940.000 s4.3%
31
if nargin <= 2
940.000 s2.9%
All other lines  0.001 s25.1%
Totals  0.006 s100% 
Children (called functions)
No children
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 run10
Code lines that did not run53
Coverage (did run/can run)15.87 %
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 
     94 
  31
if nargin <= 2 
  32 
    % The only A and B allowed are character arrays or cellstr.
  0.002 
     94 
  33
    if ~((ischar(a) || iscellstr(a)) && (ischar(b) || iscellstr(b))) 
  34 
        error(message('MATLAB:ISMEMBER:InputClass',class(a),class(b)));
< 0.001 
     94 
  35
    end 
  36 
    % Scalar A: no sort needed
  0.002 
     94 
  37
    if (ischar(a) && isrow(a)) || isscalar(a) 
< 0.001 
     94 
  38
        match = strcmp(a,b); 
< 0.001 
     94 
  39
        lia = any(match(:)); 
< 0.001 
     94 
  40
        if nargout > 1 
  41 
            if lia
  42 
                locb = find(match,1,'first');
  43 
            else
  44 
                locb = 0;
  45 
            end
< 0.001 
     94 
  46
        end 
  47 
    % Scalar B: no sort needed
  48 
    elseif (ischar(b) && isrow(b)) || isscalar(b)
  49 
        lia = strcmp(a,b);
  50 
        if nargout > 1
  51 
            locb = double(lia);
  52 
        end
  53 
    else
  54 
        % If A or B is char, convert it to a cellstr and remove trailing spaces
  55 
        if ischar(a)
  56 
            a = cellstr(a);
  57 
        end
  58 
        if ischar(b)
  59 
            b = cellstr(b);
  60 
        end
  61 
        % Duplicates within the sets are eliminated
  62 
        [uA,~,icA] = unique(a(:),'sorted');
  63 
        if nargout <= 1
  64 
            uB = unique(b(:),'sorted');
  65 
        else
  66 
            [uB,ib] = unique(b(:),'sorted');
  67 
        end
  68 
        % Sort the unique elements of A and B, duplicate entries are adjacent
  69 
        [sortuAuB,IndSortuAuB] = sort([uA;uB]);
  70 
        % d indicates the indices matching entries
  71 
        d = strcmp(sortuAuB(1:end-1),sortuAuB(2:end));
  72 
        indReps = IndSortuAuB(d);                  % Find locations of repeats
  73 
        if nargout <= 1
  74 
            lia = ismember(icA,indReps);           % Find repeats among original list
  75 
        else
  76 
            szuA = size(uA,1);
  77 
            d = find(d);
  78 
            [lia,locb] = ismember(icA,indReps);    % Find locb by using given indices
  79 
            newd = d(locb(lia));                   % NEWD is D for non-unique A
  80 
            where = ib(IndSortuAuB(newd+1)-szuA);
  81 
            locb(lia) = where;
  82 
        end
  83 
        lia = reshape(lia,size(a));
  84 
        if nargout > 1
  85 
            locb = reshape(locb,size(a));
  86 
        end
< 0.001 
     94 
  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 
     94 
 102
end 

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