Home > utils > check_unique_rows.m

check_unique_rows

PURPOSE ^

Checks whether all rows in the input matrix, mtx, are unique, and returns

SYNOPSIS ^

function [non_unique_mask, non_unique_vals] = check_unique_rows(mtx,verbose)

DESCRIPTION ^

 Checks whether all rows in the input matrix, mtx, are unique, and returns
 a mask of non-unique values and an extracted set of the non-unique values

 This function currently operates only on categorical class data

 [non_unique_mask, non_unique_vals] = check_unique_rows(mtx);

 TODO: Add support for non-categorical variables

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [non_unique_mask, non_unique_vals] = check_unique_rows(mtx,verbose)
0002 % Checks whether all rows in the input matrix, mtx, are unique, and returns
0003 % a mask of non-unique values and an extracted set of the non-unique values
0004 %
0005 % This function currently operates only on categorical class data
0006 %
0007 % [non_unique_mask, non_unique_vals] = check_unique_rows(mtx);
0008 %
0009 % TODO: Add support for non-categorical variables
0010 
0011 % 04Sep2014 - Petr Janata
0012 
0013 if nargin < 2
0014   verbose = 1;
0015 end
0016 
0017 if ~any(strcmp({'nominal','ordinal'}, class(mtx)))
0018   error('Class of input data must be nominal or ordinal')
0019 end
0020 
0021 nrows = size(mtx,1);
0022 
0023 non_unique_mask = false(nrows,1);
0024 non_unique_vals = [];
0025 
0026 uniqueRows = unique(mtx,'rows');
0027 numNonUnique = nrows - size(uniqueRows,1);
0028 if numNonUnique
0029   if verbose
0030     fprintf('Found %d non-unique rows%s\n',numNonUnique);
0031   end
0032   % Find the non-unique rows
0033   [~,idxs] = ismember(mtx,uniqueRows,'rows');
0034   
0035   % Tabulate idxs to see which appears more than once
0036   t = tabulate(idxs);
0037   
0038   % Display the nonUnique rows
0039   non_unique_vals = uniqueRows(t(:,2)>1,:);
0040   if verbose
0041     non_unique_vals
0042   end
0043   non_unique_mask = ismember(mtx,non_unique_vals,'rows');
0044 end
0045 
0046 end % function

Generated on Sun 24-Mar-2019 04:00:51 by m2html © 2003