From f2a60fee490e18705e7c447b6e86fe1a9ad60cee Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Fri, 14 Sep 2018 22:04:00 -0600 Subject: [PATCH] Excluded null values from UNIQUE enumerations --- MATLAB/beefblup.m | 4 ++-- MATLAB/uniquecell.m | 9 +++++++++ MATLAB/uniquenan.m | 10 ++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 MATLAB/uniquecell.m create mode 100644 MATLAB/uniquenan.m diff --git a/MATLAB/beefblup.m b/MATLAB/beefblup.m index 6f1848f..dbf7cca 100644 --- a/MATLAB/beefblup.m +++ b/MATLAB/beefblup.m @@ -44,7 +44,7 @@ end % Find any columns that need to be deleted for i = 7:length(headers) - if length(unique(data(:,i))) <= 1 + if length(uniquecell(data(:,i))) <= 1 colname = headers{i}; disp(['Column "' colname '" does not have any unique animals and will be removed from this analysis.']); colstodelete = [colstodelete i]; @@ -58,7 +58,7 @@ headers(colstodelete) = []; % Determine how many contemporary groups there are numgroups = ones(1, length(headers)-5); for i = 6:length(headers) - numgroups(i) = length(unique(data(:,i))); + numgroups(i-5) = length(uniquecell(data(:,i))); end % If there are more groups than animals, then the analysis cannot continue diff --git a/MATLAB/uniquecell.m b/MATLAB/uniquecell.m new file mode 100644 index 0000000..e5beae1 --- /dev/null +++ b/MATLAB/uniquecell.m @@ -0,0 +1,9 @@ +% uniquenan +% Serves the same purpose as UNIQUE, but ensures any empty cells are not +% counted +function y = uniquecell(x) +y = unique(x); +if any(cellfun(@isempty, y)) + y(cellfun(@isempty, y)) = []; +end +end \ No newline at end of file diff --git a/MATLAB/uniquenan.m b/MATLAB/uniquenan.m new file mode 100644 index 0000000..160a430 --- /dev/null +++ b/MATLAB/uniquenan.m @@ -0,0 +1,10 @@ +% uniquenan +% Serves the same purpose as UNIQUE, but ensures any NaN fields are not +% counted +function y = uniquenan(x) +y = unique(x); +if any(isnan(y)) + y(isnan(y)) = []; + y(end + 1) = NaN; +end +end \ No newline at end of file