This is a static copy of a profile report

Home

cell.unique>celluniqueR2012a (12 calls, 0.020 sec)
Generated 14-Nov-2016 07:47:21 using cpu time.
subfunction in file /usr/local/MATLAB/MATLAB_Production_Server/R2015a/toolbox/matlab/ops/@cell/unique.m
Copy to new window for comparing multiple runs

Parents (calling functions)

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

Line NumberCodeCallsTotal Time% TimeTime Plot
281
c = sortA(groupsSortA);       ...
120.010 s50.0%
330
end
120 s0%
327
if rowvec
120 s0%
294
if nargout == 3
120 s0%
285
if nargout > 1
120 s0%
All other lines  0.010 s50.0%
Totals  0.020 s100% 
Children (called functions)
No children
Code Analyzer results
Line numberMessage
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 run30
Code lines that did not run46
Coverage (did run/can run)39.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'};
     12 
 232 
if nargin == 1 
 233 
    order = 'sorted';
     12 
 234 
else 
     12 
 235 
    if options(1) > 0 
 236 
        warning(message('MATLAB:UNIQUE:RowsFlagIgnored'));     % 'rows' flag ignored for cellstrs.
 237 
    end
     12 
 238 
    if options(5) > 0 
 239 
        order = 'stable';
     12 
 240 
    elseif options(3) > 0 
 241 
        order = 'last';
     12 
 242 
    else % if options(4) > 0 || options(2) || sum(options(2:5) == 0) 
     12 
 243 
        order = 'sorted';   %'first' and 'sorted' do the same thing 
     12 
 244 
    end 
     12 
 245 
end 
 246 

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

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

     12 
 256 
a = a(:); 
 257 

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

 261 

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

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

 274 
% Extract unique elements
     12 
 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.
     12 
 280 
else 
  0.01 
     12 
 281 
    c = sortA(groupsSortA);                 % Create unique list by indexing into sorted list. 
     12 
 282 
end 
 283 

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

 293 
% Find indC.
     12 
 294 
if nargout == 3 
 295 
    if isempty(a)
 296 
        indC = zeros(0,1);
 297 
    else
 298 
        switch order
 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.
 302 
            case 'sorted'
 303 
                indC = cumsum(groupsSortA);                     % Lists position, starting at 1.
 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.
 323 
        end
 324 
    end
 325 
end
 326 

     12 
 327 
if rowvec 
 328 
    c = c.';
 329 
end
     12 
 330 
end