function longest_run_variable_thresh(inputdata)
%takes an input, figures out for a given value (x-axis) what is the max number of consecutive samples (y-axis) of the input having at least that given value

threshold=[.1:.1:5];

length_max_string_above_this_value=zeros(1,length(threshold));
for ind=1:length(threshold)
    a=find(inputdata>threshold(ind));
    b=diff(a);
    b(b~=1)=0;
    b=[0 b 0];
    [event_start_indices,event_end_indices]=threshold_crossing_start_end(b,.5);%inputdata,threshold(ind));
    if ~isempty(event_start_indices) && ~isempty(event_end_indices)
        if length(event_start_indices)>length(event_end_indices),event_start_indices=event_start_indices(1:end-1);
        elseif length(event_end_indices)>length(event_start_indices),event_end_indices=event_end_indices(2:end);
        end
        length_max_string_above_this_value(ind)=max(event_end_indices-event_start_indices)+1;
    end
end
plot(threshold,length_max_string_above_this_value/length(inputdata))