I have an array say "a"
a =
1 4 5 6 7 2
if I use the function b = sort (a)
gives ans
b =
1 4 2 6 7 5
but i want as like
5 1 4 2 6 7
the middle 2nd row should be sorted, but the elements of the ist row should remain unchanged and should correspond to row 2.
sortrows (a '2)'
Pulling it separately:
a = 1 4 5 6 7 2 a' = 1 6 4 7 5 2 sortrows(a',2) = 5 2 1 6 4 7 sortrows(a',2)' = 5 1 4 2 6 7
The key here is to sort the sorting by the specified line, all the rest follow its order.
You can use the SORT function only in the second line, and then use the index output to sort the entire array:
[junk,sortIndex] = sort(a(2,:)); b = a(:,sortIndex);
a = [1 4 5; 6 7 2] a = 1 4 5 6 7 2 >> [s,idx] = sort(a(2,:)) s = 2 6 7 idx = 3 1 2 >> b = a(:,idx) b = 5 1 4 2 6 7
In other words, you use the second argument sortto get the desired sort order, and then apply it to the whole item.
sort
Source: https://habr.com/ru/post/1759647/More articles:multiple combo boxes in R using tcltk - rjQuery $ .get (async) large file blocks browser - jqueryКак вычислить NSRange NSString в определенной позиции в UITextView - iphoneучебник eventKit - ios4memory leak detection in C ++ / windows - c ++How to check if the downloaded file is loaded using the getstore () function? - perlhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1759649/assigning-css-class-to-a-linkbutton-when-clicked-in-aspnet&usg=ALkJrhhBax2zkbAZRDyTw6GoDha3fjNUGALinux cronjob not working (execute script) - linuxUsing nmake on OSX? - macosCustom settings are not saved (Settings.Default.Save ();) - c #All Articles