An equivalent of the MS-Excel RANK function such that > [32 12 22 69 46] in a column I get the result [3 1 2 5 4]. This is > of course not the same as the indices returned from the sort function. >> x=[32 12 22 69 46] x = 32 12 22 69 46 >> [y,ind]=sort(x) y = 12 22 32 46 69 ind = 2 3 1 5 4 ind(j) = n means that the n-th entry of x is the j-th lowest value. You want to invert the map, to get a vector ind1 with the property that ind1(n) = j if and only if ind(j) = n. This will do it: >> ind1=zeros(size(x)); >> ind1(ind)=1:length(x) ind1 = 3 1 2 5 4 This will also do it, but I'm having a hard time proving to myself why it works or if it works in general: >> [y,ind1]=sort(ind) y = 1 2 3 4 5 ind1 = 3 1 2 5 4