function [weighted_output] = weight(range, ...
                                    unweighted_input, ...
                                    data_to_analyze, ...
                                    field);

k = 1;
for i=range
  m = find(unweighted_input(data_to_analyze,2) == i);
  if(length(m) > 0) 
    weighted_output(k,1) = sum( unweighted_input(data_to_analyze(m),3));
    weighted_output(k,2) = sum((unweighted_input(data_to_analyze(m),3).*  ...
                                unweighted_input(data_to_analyze(m),field))./ ...
                                  weighted_output(k,1));
  else
    weighted_output(k,1:2) = [NaN,NaN];
  end
  k = k + 1;
end
