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