function golfranks = golfrank( scores , whatsbest )
%GOLFRANK  takes scores and returns a golf-style ranking
%
%   GOLFRANK( scores )  returns the following ranking for each
%      score:  The rank will be the 1 + number of entries that 
%      have a higher score (whatsbest = 1, default) or lower 
%      score (whatsbest = 0): for example
%
%           score  =>  rank
%  [same]    2.2   ->   3.
%            2.1   ->   5.
%            2.3   ->   2.    (if whatsbest = 1)
%  [same]    2.2   ->   3.
%            2.6   ->   1.
%
%  Last change:  10/2/2005 - Florian Knorn

if nargin ~= 1 && nargin ~= 2
	error('please provide at least the scores');
elseif nargin == 1
	whatsbest = true;
end

golfranks = [];

if whatsbest % bigger is better
	for i=1:length(scores)
		golfranks(i) = 1 + length( find(scores > scores(i)) );
	end
else
	for i=1:length(scores)
		golfranks(i) = 1 + length( find(scores < scores(i)) );
	end
end

golfranks = golfranks'; % make sure it's a column-vector