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 for next small value rank2 and so on)
2.For zero cell rank1 is given.
3.Other than diagonal cell and zero cell we sort rest values in ascending order.(Number of zero cells will be set as initial rank order i.e zero cells rank first)
Main example
This is my input matrix.
0.6667 0.1667 0.1667 0 0.6667
0.1667 0.1667 0.1667 0 0.1667
0.1667 0.1667 0.1667 0 0.1667
0 0 0 0 0
0.6667 0.1667 0.1667 0 1.0000
expected output matrix is:
4 2 3 1 4
4 3 3 1 2
4 3 2 1 2
1 1 1 1 1
4 3 2 1 5
But i got this output matrix for my code:
4 1 4 0 2
3 2 4 0 1
3 4 3 0 1
0 0 0 0 0
4 3 2 0 5
Source code i tried:
%to display ordinal graph
E = logical(eye(size(table1)));
% create a mask for the two different rules
% rule 1: diagonal elements first
table2 = zeros(size(table1)); % create result matrix
[~,jj] = sort(table1(E));
[~,ii] = sort(jj);
table2(E) = ii; % assign rank of diagonal elements
% rule 2: rest of the matrix
E = ~E;
B = reshape(table1(E),size(table1,1)-1,size(table1,2))'; % B is the matrix of table1 without diagonal elements
[~,jj] = sort(B,2); % sort along column dimension,
[~,ii] = sort(jj,2);
table2 = table2'; % matlab is column-major, so you have to transpose the dest matrix before putting in the elements
table2(E) = reshape(ii',[],1);
table2 = table2'; % transpose back, done.
% treat zeros apart: 0 has rank 0
table2(table1==0) = 0;
disp(table2);
Example 1
Input matrix:
12 6 6 4 12
6 6 6 4 6
6 6 6 4 6
4 4 4 4 4
12 6 6 4 16
Expected output matrix:
4 3 2 1 4
4 3 2 1 3
4 3 2 1 2
4 3 2 1 1
4 3 2 1 5
Example 2
Input matrix:
10 11 0 13 14
14 9 8 20 7
20 25 22 18 13
16 8 9 23 19
15 0 0 16 21
Expected output matrix:
2 2 1 3 4
3 1 2 4 1
3 4 4 2 1
3 1 2 5 4
2 1 1 3 3
3.Other than diagonal cell ..
? That part isn't clear to me with respect to the expected values even. – Divakar3 2 3 0 4
instead. – DivakarOne more example #1
, as the input you have as the fourth row4 4 4 4 4
and your output for it is4 3 2 1 1
. Using MATLAB it would be1 2 3 1 4
. So it appears you are doing something different. How are you even getting these expected outputs? By hand calculations? – Divakar