필터 지우기
필터 지우기

sorting array with condition (paths sorting)

조회 수: 7 (최근 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)=[]

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by