1
0
Fork 0
mirror of https://github.com/MillironX/beefblup.git synced 2024-12-22 09:08:16 +00:00

Excluded null values from UNIQUE enumerations

This commit is contained in:
Thomas A. Christensen II 2018-09-14 22:04:00 -06:00
parent 6743790804
commit f2a60fee49
3 changed files with 21 additions and 2 deletions

View file

@ -44,7 +44,7 @@ end
% Find any columns that need to be deleted % Find any columns that need to be deleted
for i = 7:length(headers) for i = 7:length(headers)
if length(unique(data(:,i))) <= 1 if length(uniquecell(data(:,i))) <= 1
colname = headers{i}; colname = headers{i};
disp(['Column "' colname '" does not have any unique animals and will be removed from this analysis.']); disp(['Column "' colname '" does not have any unique animals and will be removed from this analysis.']);
colstodelete = [colstodelete i]; colstodelete = [colstodelete i];
@ -58,7 +58,7 @@ headers(colstodelete) = [];
% Determine how many contemporary groups there are % Determine how many contemporary groups there are
numgroups = ones(1, length(headers)-5); numgroups = ones(1, length(headers)-5);
for i = 6:length(headers) for i = 6:length(headers)
numgroups(i) = length(unique(data(:,i))); numgroups(i-5) = length(uniquecell(data(:,i)));
end end
% If there are more groups than animals, then the analysis cannot continue % If there are more groups than animals, then the analysis cannot continue

9
MATLAB/uniquecell.m Normal file
View file

@ -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

10
MATLAB/uniquenan.m Normal file
View file

@ -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