From: IDSC Badr on
"Don " <yates(a)lsua.edu> wrote in message <fnvdkf$set$1(a)fred.mathworks.com>...
> Thanks in advance
>
> I need to generate the rank order of a vector like the
> Excel RANK function. I.E.
>
> Highest Number -> 1
> Second Highest -> 2
> etc.
>
> I'm hoping that there's one in the library and I don't have
> to write one.
>
>
Dear don
Please try this piece of code

function [ ranked ] = rank(vector)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
sorted_vector = sort(vector);
ranked = 1:length(vector);

for i=2:length(vector)
location = find(sorted_vector==sorted_vector(i));
if length(location)>1
for j=1:length(location)
ranked(location(j)) = sum(location)/length(location);
end
else
ranked(i) = i;
end
end

end


mail me if problems amabadr(a)idsc.net.eg