Borrar filtros
Borrar filtros

sorting array with condition (paths sorting)

7 visualizaciones (últimos 30 días)
mohammed sportman
mohammed sportman el 6 de En. de 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]

Respuesta aceptada

Matt J
Matt J el 6 de En. de 2013
b=[a,sum(logical(a),2)];
result=sortrows(b,[1,2,size(b,2)]);
result(:,end)=[]

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by