sortrows descend not working
Afficher commentaires plus anciens
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

2 commentaires
Stephen23
le 4 Fév 2021
"The first four columns of rows 6 and 7 have the same values..."
My guess is that they don't have the same values. Lets check properly, show us the output of this command:
up2(7,:) - up2(6,:)
Sezer Yasar
le 4 Fév 2021
Modifié(e) : Sezer Yasar
le 4 Fév 2021
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!