Sort Matrix by rows
    10 ビュー (過去 30 日間)
  
       古いコメントを表示
    
I have a matrix which first row indicates index numbers and second indicated the data. For example it goes like this:
1    2    3    4    5    6
23   45   10   90   11   34
I want to sort these descending but I don't want to loose the corresponding index either.
4    2    6    1    5    3
90   45   34   23   11   10
I have a large amount of data so it needs to be efficient too. How can I do that?
0 件のコメント
採用された回答
その他の回答 (3 件)
  Torsten
      
      
 2014 年 10 月 23 日
        B=(sortrows(A',-2))';
where A is your input matrix.
Best wishes
Torsten.
0 件のコメント
  Geoff Hayes
      
      
 2014 年 10 月 23 日
        Ege - consider using sortrows to perform the above task
 A = [1    2    3    4    5    6
     23   45   10   90   11   34];
 B = sortrows(A',-2)';
We transpose A so that we can sort on the second column. The negative indicates descending sort order. The result is then transposed to get the desired output as
 B =
     4     2     6     1     5     3
    90    45    34    23    11    10
0 件のコメント
参考
カテゴリ
				Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



