Hello,
I have a matrix created in Matlab and I want to sort its rows in descending order, keeping the rows unchanged. Specifically, I want to sort rows according to value in the first column in descending order; if two rows have the same values in the first column, I want to sort the rows in descending order according to the value in the second column; and so on.
My matrix's name is "up2" and I am using the code "up2=sortrows(up2,'descend');" to obtain the sorted matrix. However, as the figure below shows sorting is not working. The figure is showing the sorted matrix after I run the code. The first four columns of rows 6 and 7 have the same values, so accroding to the values in column five row 6 should be below row 7, but it is not.
Can you please help to fix the problem? Thanks!
By the way, if it is related, col4=1-col5+col10 and col10=1-col8+col1.*log(col6+col9). When I copy the values of the first four columns here, the two rows seem to have exactly the same values:
col1 col2 col3 col4
1.20000000000000 0.100000000000000 0.200000000000000 0.832227738422948
1.20000000000000 0.100000000000000 0.200000000000000 0.832227738422948
Best Answer