-4

This first matrix table1 contains normalized values for 5 names.I need to perform some operations on this matrix and I have to obtain second matrix as shown in table2.

Diagonal elements of table2 should obtained by giving rank(ordinal value) to each value.That means highest element is given 5th rank and next highest is given 4th 3rd and so on.

   OPERATION:For diagonal elements
   B(1,1)=5(first largest element)
   B(2,2)=1(5th largest element)
   B(3,3)=4(4th largest element)
   B(4,4)=2(2nd largest element)
   B(5,5)=3(3rd largest element)
  Table1:
                   BASAVARAJ      MANOJ   NATESH        VIJAY       GOWDA

  BASAVARAJ      1.0000       0.2727      0.3182       0.0455        0.2727

  MANOJ         0.2727         0.2727        0           0             0

 NATESH         0.3182           0    0.4545       0.1818          0

  VIJAY         0.0455           0    0.1818       0.2727        0.0909

  GOWDA         0.2727           0       0         0.0909        0.3636


 Table2:
                  BASAVARAJ    MANOJ   NATESH   VIJAY   GOWDA


  BASAVARAJ             5          0    0   0   0
    MANOJ               0          1    0   0   0
   NATESH               0          0    4   0   0
   VIJAY                0          0    0   2   0
   GOWDA                0          0    0   0   3
prash2
  • 25
  • 2
  • 10
  • See also http://stackoverflow.com/questions/23234608/matlab-code-for-given-matrix-using-for-loop-by-adding-rows-and-finding-minimum-v and http://stackoverflow.com/questions/23262264/sorting-matrix-diagonal-wise-and-indexes-are-given-as-rank-using-matlab did the answer given help? What have you tried so far, why didn't it work? – David Apr 25 '14 at 07:45

2 Answers2

0

Try this:

da = diag(A); % A is your first matrix
[sda, I] = sort(da);;
for i = 1:length(da)
  B(I(i)) = i;
end
B = diag(B) % B is your second matrix
SamuelDSR
  • 28
  • 5
0
[~, ii] = sort(diag(table1));
[~, jj] = sort(ii);
table2 = diag(jj);
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147