Ranking matrix values in ascending order in matlab

后端 未结 1 1281
误落风尘
误落风尘 2021-01-23 23:20

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

相关标签:
1条回答
  • 2021-01-23 23:57

    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
    
    0 讨论(0)
提交回复
热议问题