function [states,theta_loc,filtered_theta] = states_comp(B,th,Theta_)
A = Theta_(B>th);


A = sort(A);

% Find the differences between consecutive elements
differences = diff(A);

% Create a logical index to keep the first element of each group where the difference is less than 2
indexToKeep = [true, differences >= 2];

% Use logical indexing to get the filtered array
filtered_theta= A(indexToKeep);
theta_loc = find(ismember(Theta_,filtered_theta));
states = numel(filtered_theta);


    
end