This is a static copy of a profile report

Home

cell.unique>celluniqueR2012a (Calls: 6, Time: 0.004 s)
Generated 04-Jun-2021 04:11:23 using performance time.
subfunction in file C:\Program Files\MATLAB\R2020b\toolbox\matlab\ops\@cell\unique.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
cell.uniquefunction6
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
263
groupsSortA = ~strcmp(sortA(1:...
60.001 s15.1%
281
c = sortA(groupsSortA);       ...
60.001 s14.5%
303
indC = cumsum(groupsSortA);   ...
40.001 s12.8%
289
indA = indSortA(groupsSortA); ...
60.000 s11.6%
248
if any(cellfun('size',a(:),1)&...
60.000 s7.7%
All other lines  0.002 s38.2%
Totals  0.004 s100% 
Children (called functions)
No children
Code Analyzer results
Line numberMessage
317Extra semicolon is unnecessary in IF statement before newline.
Coverage results
Show coverage for parent directory
Total lines in function103
Non-code lines (comments, blank lines)27
Code lines (lines that can run)76
Code lines that did run49
Code lines that did not run27
Coverage (did run/can run)64.47 %
Function listing
time 
Calls 
 line
 228 
function [c,indA,indC] = celluniqueR2012a(a,options)
 229 
% 'R2012a' flag implementation
 230 

 231 
% flagvals = {'rows' 'first' 'last' 'sorted' 'stable'};
< 0.001 
      6 
 232
if nargin == 1 
< 0.001 
      2 
 233
    order = 'sorted'; 
< 0.001 
      4 
 234
else 
< 0.001 
      4 
 235
    if options(1) > 0 
 236 
        warning(message('MATLAB:UNIQUE:RowsFlagIgnored'));     % 'rows' flag ignored for cellstrs.
< 0.001 
      4 
 237
    end 
< 0.001 
      4 
 238
    if options(5) > 0 
 239 
        order = 'stable';
< 0.001 
      4 
 240
    elseif options(3) > 0 
 241 
        order = 'last';
< 0.001 
      4 
 242
    else % if options(4) > 0 || options(2) || sum(options(2:5) == 0) 
< 0.001 
      4 
 243
        order = 'sorted';   %'first' and 'sorted' do the same thing 
< 0.001 
      4 
 244
    end 
< 0.001 
      6 
 245
end 
 246 

 247 
% check if input is an array with each element a single row text array.
< 0.001 
      6 
 248
if any(cellfun('size',a(:),1)>1) 
 249 
    error(message('MATLAB:UNIQUE:NotARowVector'));
< 0.001 
      6 
 250
end 
 251 

 252 
% Determine if A is a row vector and the number of elements of A.
< 0.001 
      6 
 253
rowvec = isrow(a); 
< 0.001 
      6 
 254
numelA = numel(a); 
 255 

< 0.001 
      6 
 256
a = a(:); 
 257 

 258 
% Sort A and get indices.
< 0.001 
      6 
 259
[sortA,indSortA] = sort(a); 
 260 

 261 

 262 
% groupsSortA indicates the location of non-matching entries.
< 0.001 
      6 
 263
groupsSortA = ~strcmp(sortA(1:end-1),sortA(2:end)); 
< 0.001 
      6 
 264
groupsSortA = groupsSortA(:); 
 265 

< 0.001 
      6 
 266
if ~isempty(a) 
< 0.001 
      6 
 267
    if strcmp(order, 'last')  
 268 
        groupsSortA = [groupsSortA; true];      % Final element is always a member of unique list.
< 0.001 
      6 
 269
    else % strcmp(order, 'sorted') || strcmp(order, 'stable') 
< 0.001 
      6 
 270
        groupsSortA = [true;groupsSortA];       % First element is always a member of unique list. 
< 0.001 
      6 
 271
    end 
< 0.001 
      6 
 272
end 
 273 

 274 
% Extract unique elements
< 0.001 
      6 
 275
if strcmp(order, 'stable')  
 276 
    invIndSortA = indSortA;
 277 
    invIndSortA(invIndSortA) = 1:numelA;    % Find inverse permutation.
 278 
    logIndA = groupsSortA(invIndSortA);     % Create new logical by indexing into groupsSortA.
 279 
    c = a(logIndA);                         % Create unique list by indexing into unsorted a.
< 0.001 
      6 
 280
else 
< 0.001 
      6 
 281
    c = sortA(groupsSortA);                 % Create unique list by indexing into sorted list. 
< 0.001 
      6 
 282
end 
 283 

 284 
% Find indA.
< 0.001 
      6 
 285
if nargout > 1 
< 0.001 
      6 
 286
    if strcmp(order, 'stable') 
 287 
        indA = find(logIndA);               % Find the indices of the unsorted logical.
< 0.001 
      6 
 288
    else 
< 0.001 
      6 
 289
        indA = indSortA(groupsSortA);       % Find the indices of the sorted logical. 
< 0.001 
      6 
 290
    end 
< 0.001 
      6 
 291
end 
 292 

 293 
% Find indC.
< 0.001 
      6 
 294
if nargout == 3 
< 0.001 
      4 
 295
    if isempty(a) 
 296 
        indC = zeros(0,1);
< 0.001 
      4 
 297
    else 
< 0.001 
      4 
 298
        switch order 
< 0.001 
      4 
 299
            case 'last' 
 300 
                indC = cumsum([1;groupsSortA(1:end-1)]);        % Lists position, starting at 1.
 301 
                indC(indSortA) = indC;                          % Re-reference indC to indexing of sortA.
< 0.001 
      4 
 302
            case 'sorted' 
< 0.001 
      4 
 303
                indC = cumsum(groupsSortA);                     % Lists position, starting at 1. 
< 0.001 
      4 
 304
                indC(indSortA) = indC;                          % Re-reference indC to indexing of sortA. 
 305 
            otherwise % 'stable'
 306 
                [~,indSortC] = sort(c);                         % Sort C to get index.
 307 
                
 308 
                lengthGroupsSortA = diff(find([groupsSortA; true]));    % Determine how many of each of the above indices there are in IC.
 309 
                
 310 
                diffIndSortC = diff(indSortC);                          % Get the correct amount of each index.
 311 
                diffIndSortC = [indSortC(1); diffIndSortC];
 312 
                
 313 
                indLengthGroupsSortA = cumsum([1; lengthGroupsSortA]);
 314 
                indLengthGroupsSortA(end) = [];
 315 
                
 316 
                indCOrderedBySortA(indLengthGroupsSortA,1) = diffIndSortC;        % Since indCOrderedBySortA is not already established as a column,
 317 
                if sum(lengthGroupsSortA) ~= length(indCOrderedBySortA);
 318 
                    indCOrderedBySortA(sum(lengthGroupsSortA),1) = 0;
 319 
                end
 320 
                
 321 
                indCOrderedBySortA = cumsum(indCOrderedBySortA);
 322 
                indC = indCOrderedBySortA(invIndSortA);                 % Reorder the list of indices to the unsorted order.
< 0.001 
      4 
 323
        end 
< 0.001 
      4 
 324
    end 
< 0.001 
      6 
 325
end 
 326 

< 0.001 
      6 
 327
if rowvec 
 328 
    c = c.';
< 0.001 
      6 
 329
end 
< 0.001 
      6 
 330
end 

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