This is a static copy of a profile report

Home

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

Parents (calling functions)

Function NameFunction TypeCalls
FastVarOpts>FastVarOpts.setTypesclass method2
setxor>setxorR2012asubfunction4
...tInputs>SpreadsheetInputs.setSheetclass method4
cell.ismemberfunction2
...ategorical>categorical.categoricalclass method1
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
95
lia = ismemberR2012a(A,B);
60.017 s56.3%
97
[lia,locb] = ismemberR2012a(A,...
30.006 s19.8%
142
lia = ismemberR2012a(A,B,logic...
40.001 s4.3%
113
foundflag = matlab.internal.ma...
40.001 s3.6%
93
if nargin <= 2
130.000 s1.2%
All other lines  0.004 s14.8%
Totals  0.030 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
ismember>ismemberR2012asubfunction130.023 s75.9%
partialMatchStringfunction40.001 s2.6%
Self time (built-ins, overhead, etc.)  0.006 s21.5%
Totals  0.030 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function160
Non-code lines (comments, blank lines)66
Code lines (lines that can run)94
Code lines that did run46
Code lines that did not run48
Coverage (did run/can run)48.94 %
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 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 = ISMEMBER(A,B,'rows') for matrices A and B with the same number
   8 
%   of columns, returns a vector containing true where the rows of A are
   9 
%   also rows of B and false otherwise.
  10 
%
  11 
%   [LIA,LOCB] = ISMEMBER(A,B) also returns an array LOCB containing the
  12 
%   lowest absolute index in B for each element in A which is a member of
  13 
%   B and 0 if there is no such index.
  14 
%
  15 
%   [LIA,LOCB] = ISMEMBER(A,B,'rows') also returns a vector LOCB containing
  16 
%   the lowest absolute index in B for each row in A which is a member
  17 
%   of B and 0 if there is no such index.
  18 
%
  19 
%   The behavior of ISMEMBER has changed.  This includes:
  20 
%     -	occurrence of indices in LOCB switched from highest to lowest
  21 
%     -	tighter restrictions on combinations of classes
  22 
%
  23 
%   If this change in behavior has adversely affected your code, you may
  24 
%   preserve the previous behavior with:
  25 
%
  26 
%      [LIA,LOCB] = ISMEMBER(A,B,'legacy')
  27 
%      [LIA,LOCB] = ISMEMBER(A,B,'rows','legacy')
  28 
%
  29 
%   Examples:
  30 
%
  31 
%      a = [9 9 8 8 7 7 7 6 6 6 5 5 4 4 2 1 1 1]
  32 
%      b = [1 1 1 3 3 3 3 3 4 4 4 4 4 9 9 9]
  33 
%
  34 
%      [lia1,locb1] = ismember(a,b)
  35 
%      % returns
  36 
%      lia1 = [1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1]
  37 
%      locb1 = [14 14 0 0 0 0 0 0 0 0 0 0 9 9 0 1 1 1]
  38 
%
  39 
%      [lia,locb] = ismember([1 NaN 2 3],[3 4 NaN 1])
  40 
%      % NaNs compare as not equal, so this returns
  41 
%      lia = [1 0 0 1], locb = [4 0 0 1]
  42 
%
  43 
%   Class support for inputs A and B, where A and B must be of the same
  44 
%   class unless stated otherwise:
  45 
%      - logical, char, all numeric classes (may combine with double arrays)
  46 
%      - cell arrays of strings (may combine with char arrays)
  47 
%      -- 'rows' option is not supported for cell arrays
  48 
%      - objects with methods SORT (SORTROWS for the 'rows' option), EQ and NE
  49 
%      -- including heterogeneous arrays derived from the same root class
  50 
%
  51 
%   See also ISMEMBERTOL, INTERSECT, UNION, UNIQUE, UNIQUETOL, SETDIFF,
  52 
%            SETXOR, SORT, SORTROWS.
  53 

  54 
%   Copyright 1984-2020 The MathWorks, Inc.
  55 

  56 
% Convert string flags to char flags to dispatch to the right method
< 0.001 
     13 
  57
if nargin == 3 && isstring(flag1) 
  58 
    flag1 = convertFlag(flag1);
  59 
    if nargout < 2
  60 
        lia = ismember(A, B, flag1);
  61 
    else
  62 
        [lia, locb] = ismember(A, B, flag1);
  63 
    end
  64 
    return
< 0.001 
     13 
  65
end 
< 0.001 
     13 
  66
if nargin == 4 && (isstring(flag1) || isstring(flag2)) 
  67 
    if isstring(flag1)
  68 
        flag1 = convertFlag(flag1);
  69 
    end
  70 
    if isstring(flag2)
  71 
        flag2 = convertFlag(flag2);
  72 
    end
  73 
    if nargout < 2
  74 
        lia = ismember(A, B, flag1, flag2);
  75 
    else
  76 
        [lia, locb] = ismember(A, B, flag1, flag2);
  77 
    end
  78 
    return
< 0.001 
     13 
  79
end 
  80 

< 0.001 
     13 
  81
if (isstring(A) || isstring(B)) 
< 0.001 
      3 
  82
    if ~ischar(A) && ~iscellstr(A) && ~isstring(A) 
  83 
        firstInput = getString(message('MATLAB:string:FirstInput'));
  84 
        error(message('MATLAB:string:MustBeCharCellArrayOrString', firstInput));
< 0.001 
      3 
  85
    elseif ~ischar(B) && ~iscellstr(B) && ~isstring(B) 
  86 
        secondInput = getString(message('MATLAB:string:SecondInput'));
  87 
        error(message('MATLAB:string:MustBeCharCellArrayOrString', secondInput));
< 0.001 
      3 
  88
    end 
< 0.001 
      3 
  89
    A = string(A); 
< 0.001 
      3 
  90
    B = string(B); 
< 0.001 
     13 
  91
end 
  92 

< 0.001 
     13 
  93
if nargin <= 2 
< 0.001 
      9 
  94
    if nargout < 2 
  0.017 
      6 
  95
        lia = ismemberR2012a(A,B); 
< 0.001 
      3 
  96
    else 
  0.006 
      3 
  97
        [lia,locb] = ismemberR2012a(A,B); 
< 0.001 
      9 
  98
    end 
< 0.001 
      4 
  99
else 
 100 
    % acceptable combinations, with optional inputs denoted in []
 101 
    % ismember(A,B, ['rows'], ['legacy'/'R2012a'])
< 0.001 
      4 
 102
    nflagvals = 3; 
< 0.001 
      4 
 103
    flagvals = ["rows", "legacy", "R2012a"]; 
 104 
    % When a flag is found, note the index into varargin where it was found
< 0.001 
      4 
 105
    flaginds = zeros(1,nflagvals); 
< 0.001 
      4 
 106
    for i = 3:nargin 
< 0.001 
      4 
 107
        if i == 3 
< 0.001 
      4 
 108
            flag = flag1; 
 109 
        else
 110 
            flag = flag2;
< 0.001 
      4 
 111
        end 
< 0.001 
      4 
 112
        assert(~isstring(flag)); 
  0.001 
      4 
 113
        foundflag = matlab.internal.math.partialMatchString(flag,flagvals); 
< 0.001 
      4 
 114
        if ~any(foundflag) 
 115 
            if ischar(flag)
 116 
                error(message('MATLAB:ISMEMBER:UnknownFlag',flag));
 117 
            else
 118 
                error(message('MATLAB:ISMEMBER:UnknownInput'));
 119 
            end
< 0.001 
      4 
 120
        end 
 121 
        % Only 1 occurrence of each allowed flag value
< 0.001 
      4 
 122
        if flaginds(foundflag) 
 123 
            error(message('MATLAB:ISMEMBER:RepeatedFlag',flag));
      4 
 124
        end 
< 0.001 
      4 
 125
        flaginds(foundflag) = i; 
< 0.001 
      4 
 126
    end 
 127 
    
 128 
    % Only 1 of each of the paired flags
< 0.001 
      4 
 129
    if flaginds(2) && flaginds(3) 
 130 
        error(message('MATLAB:ISMEMBER:BehaviorConflict'))
< 0.001 
      4 
 131
    end 
 132 
    % 'legacy' and 'R2012a' flags must be trailing
< 0.001 
      4 
 133
    if flaginds(2) && flaginds(2)~=nargin 
 134 
        error(message('MATLAB:ISMEMBER:LegacyTrailing'))
< 0.001 
      4 
 135
    end 
< 0.001 
      4 
 136
    if flaginds(3) && flaginds(3)~=nargin 
 137 
        error(message('MATLAB:ISMEMBER:R2012aTrailing'))
< 0.001 
      4 
 138
    end 
 139 
    
< 0.001 
      4 
 140
    if flaginds(3) % trailing 'R2012a' specified 
< 0.001 
      4 
 141
        if nargout < 2 
  0.001 
      4 
 142
            lia = ismemberR2012a(A,B,logical(flaginds(1))); 
 143 
        else
 144 
            [lia,locb] = ismemberR2012a(A,B,logical(flaginds(1)));
< 0.001 
      4 
 145
        end 
 146 
    elseif flaginds(2) % trailing 'legacy' specified
 147 
        if nargout < 2
 148 
            lia = ismemberlegacy(A,B,logical(flaginds(1)));
 149 
        else
 150 
            [lia,locb] = ismemberlegacy(A,B,logical(flaginds(1)));
 151 
        end
 152 
    else % 'R2012a' (default behavior)
 153 
        if nargout < 2
 154 
            lia = ismemberR2012a(A,B,logical(flaginds(1)));
 155 
        else
 156 
            [lia,locb] = ismemberR2012a(A,B,logical(flaginds(1)));
 157 
        end
      4 
 158
    end 
< 0.001 
     13 
 159
end 
< 0.001 
     13 
 160
end 

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