0

I really need help:(

I have a 2x367 matrix, where the first entry in each row indicates the number of the feature and the second one the number of occurences. I managed to sort them row by row, but I want to sort them pairwise.

So my data looks like:

2490   1
  44   512   ......

indicating that I have feature 2490 44 times and 1 512 times. I want to put feature 1 in front but together with the 512..Thanks!

Laurie
  • 53
  • 9
  • Possible duplicate of [How can I sort a 2-D array in MATLAB with respect to one column?](http://stackoverflow.com/questions/134712/how-can-i-sort-a-2-d-array-in-matlab-with-respect-to-one-column) – sco1 Jul 12 '16 at 18:56

2 Answers2

2

Here is another elegant way (in my opinion):

y = sortrows(x', 1)';
Prakhar
  • 325
  • 1
  • 9
1

If your expected output is:

  1        2490
 512          44

you ca use the sort function:

[a,b]=sort(x(1,:))
k=[a;x(2,b)]

The function sort returns as first output the sorted values (in this case the sorte3d values of the first row) and as second output the position index.

You can use the position index to "align" the data of the second row.

Hope this helps.

Qapla'

il_raffa
  • 5,090
  • 129
  • 31
  • 36