Effacer les filtres
Effacer les filtres

sorting array with condition (paths sorting)

7 vues (au cours des 30 derniers jours)
mohammed sportman
mohammed sportman le 6 Jan 2013
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]

Réponse acceptée

Matt J
Matt J le 6 Jan 2013
b=[a,sum(logical(a),2)];
result=sortrows(b,[1,2,size(b,2)]);
result(:,end)=[]
  1 commentaire
mohammed sportman
mohammed sportman le 7 Jan 2013
thanks thanks Matt . i am very happy .

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by