sorting array with condition (paths sorting)

3 ビュー (過去 30 日間)
mohammed sportman
mohammed sportman 2013 年 1 月 6 日
i want sort function to sort the element of matrix except the 1&2 column still fixed. depending at the length of each row (except 0)
like that
a=[1 2 5 2 1 0 0
1 2 3 4 0 0 0
1 2 4 0 0 0 0
1 3 2 0 0 0 0
1 3 3 1 4 0 0
1 3 4 5 0 0 0
2 1 4 5 0 0 0
2 1 3 0 0 0 0]
the first row contain 3 element (after 1&2 column except 0)
the second row contain 2 element
the third row contain 1 element
after sorting
a= [ 1 2 4 0 0 0 0
1 2 3 4 0 0 0
1 2 5 2 1 0 0
1 3 2 0 0 0 0
1 3 4 5 0 0 0
1 3 3 1 4 0 0
2 1 3 0 0 0 0
2 1 4 5 0 0 0]

採用された回答

Matt J
Matt J 2013 年 1 月 6 日
b=[a,sum(logical(a),2)];
result=sortrows(b,[1,2,size(b,2)]);
result(:,end)=[]
  1 件のコメント
mohammed sportman
mohammed sportman 2013 年 1 月 7 日
thanks thanks Matt . i am very happy .

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by