/usr/share/psychtoolbox-3/PsychOneliners/UniqueCell.m is in psychtoolbox-3-common 3.0.14.20170103+git6-g605ff5c.dfsg1-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | function [y,ia,ic] = UniqueCell(x)
% UniqueCell Get unique rows from cell array
%
% Description: like unique(x,'rows'), but supports cell arrays, and these
% cell arrays can have columns with different types
%
% Usage: [Y,IA,IC] = UniqueCell(X)
%
% Input:
% X: the cell array to be processed.
%
% Output:
% Y: contains the same values as in A but with no repetitions. Y will
% be sorted.
% IA: index vector IA such that C = A(IA,:).
% IC: index vector IC such that A = C(IC,:).
%
% Note that this function has only been tested on mixed cell arrays
% containing character strings and numeric values.
% Copyright 2007 Diederick C. Niehorster (Lund University, Sweden)
% Check input arguments
if ~iscell(x)
error('the first input argument is not a cell array. a cell array is expected.');
end
% sort input, get indices
[sortX,indSortX] = SortCell(x,1:size(x,2));
% per column, find out where the values change
groupsSortX = false(size(sortX,1)-1,size(sortX,2));
for p=1:size(sortX,2)
if iscellstr(sortX(:,p))
groupsSortX(:,p) = ~strcmp(sortX(1:end-1,p),sortX(2:end,p));
else
groupsSortX(:,p) = cat(1,sortX{1:end-1,p}) ~= cat(1,sortX{2:end,p});
end
end
groupsSortX = any(groupsSortX,2);
groupsSortX = [true; groupsSortX]; % First row is always a member of unique list.
% Extract Unique elements.
y = sortX(groupsSortX,:); % Create unique list by indexing into sorted list.
% Find ia.
if nargout > 1
ia = indSortX(groupsSortX); % Find the indices of the sorted logical.
end
% Find ic.
if nargout == 3
ic = cumsum(groupsSortX); % Lists position, starting at 1.
ic(indSortX) = ic; % Re-reference indC to indexing of sortA.
end
|