function [segments_start, segments_end, segments_value] = enumerate_continuous_segments(logical_vector)
%ENUMERATE_CONTINUOUS_SEGMENTS enumerates continuous segments of equal
%   truth values

    if ~isvector(logical_vector) || ~islogical(logical_vector)
        error('cvp:enumerate_continuous_segments:not_logical_vector', 'logical_vector is not a logical vector');
    end

   if isempty(logical_vector)
	error('cvp:enumerate_continuous_segments:logical_vector_empty', 'logical_vector is empty');
   end

    logical_vector = reshape(logical_vector, 1, length(logical_vector));
    change_vector = diff([~logical_vector(1) logical_vector ~logical_vector(end)]);
    segment_borders = find(change_vector);

    segments_start = segment_borders(1:(end-1));
    segments_end = segment_borders(2:end) - 1;
    segments_value = logical_vector(floor((segments_start + segments_end) ./ 2));
end
% Author: Jan F. Kraemer <jan.kraemer@rwth-aachen.de>
%
