function averaged_vals=mean_with_preference_for_precedents(value_vector,index_vector,number_of_values_to_average)
%finds averages 'looking backward' where possible
%called by analyze_sd_over_time

averaged_vals=repmat(nan,1,length(value_vector));
for z=number_of_values_to_average:length(index_vector)
    averaged_vals(index_vector(z))=mean(value_vector(index_vector((z-(number_of_values_to_average-1)):z)));
end
for y=1:number_of_values_to_average-1
    averaged_vals(index_vector(y))=mean(value_vector(index_vector(1:number_of_values_to_average)));
end      