function [strag] = stragglers3d(M,S);
% STRAGGLERS3d(M,S) --- Finds the proportion of points in array 'M' which are stragglers,
% i.e. that are not in a group.  Groups are defined by the 'findgroups3d' function, of 
% which 'S' is the structure output, containing the members for each group.

%Based on 'stragglers' by Ian McFarland.  Modified by Jim Work, University
%of South Carolina, August 13th, 2003.

% First, a counter is initialized.
count = 0;

% Next, the size of each group in the structure 'S' will be checked; if the size (n)
% is 1, one will be added to the count.  
for i = 1:size(S,2)
    
    G = S(i).members;               % Pulls a group out of M. 
    
    n = size(G,2);                  % Finds the size of that group.
    
    if n == 1                       % Check to see if it's a straggler. If so, 
        count = count + 1;          %  the count is advanced.
    end
end

% Finally, the count of stragglers is divided by the total number in the array to 
% get the proportion.
strag = count/size(M,1);
