function segs=segment_seeker(begin_points,end_points,find_unique_segments)
%description: takes a vector of candidate start points for segments and a vector of candidate end points
    %finds the shortest segment possible for each candidate end point that can actually be used, or, if not instructed to find unique segments, find each possible start point followed by each possible endpoint
%called by: noise_segmenter
%calls: no custom functions
%notes:
%code_confirmed_date: july 16, 2012

segs=[0;0];
if find_unique_segments
	for iii=1:length(begin_points)
        if any(end_points>begin_points(iii))
            candidate_end_points=end_points(find(end_points>begin_points(iii)));candidate_end=candidate_end_points(1);  %getting the nearest possible end point
            if iii~=length(begin_points)
                if ~(begin_points(iii+1)<candidate_end)         %making sure this begin point is the nearest possible begin point preceding this end point
                    segs=[segs [begin_points(iii);candidate_end]];
                end
            else
                segs=[segs [begin_points(iii);candidate_end]];
            end        
        end
	end
else 
    for iii=1:length(begin_points)
        if any(end_points>begin_points(iii))
            endds=end_points(find(end_points>begin_points(iii)));
            for jjj=1:length(endds)
                segs=[segs [begin_points(iii);endds(jjj)]];
            end
        end
	end
end
segs(:,1)=[];