For given matrix R={r(i,j)} following are the 3 operations done for input matrix:
1.We rank diagonal values in ascending order.(i.e for small value rank 1 is given and f
It seems there are issues with the way indices are presented in the question when dealing with sorting identical values, but assuming this won't affect the end results, you may try this for 5x5 matrices -
%%// A is your input matrix
%%// Pre-allocate output matrix
out = zeros(size(A));
%%// Take care of operation #3
for k = 1:5
[~,ind2] = sort(A(k,:))
ind2(ind2)=1:5;
out(k,:) = ind2;
end
out = out-bsxfun(@gt,out,diag(out))
%%// Take care of assigning diagonal elements
[~,ind1] = sort(diag(A))
ind1(ind1)=1:5
out(1:size(out,1)+1:end)=ind1