how sort just nonzero values?

how can sort values except zero values i.e i want to sort just non zero values in c. how do that. c=[8 4 5 1 0 0 0 ];
thanks

 Respuesta aceptada

Honglei Chen
Honglei Chen el 12 de Mzo. de 2012

0 votos

Do you want to keep all zeros at the original location? If so
c = [8 4 5 1 0 0 0];
c(c~=0) = sort(c(c~=0));

Más respuestas (1)

Jonathan Sullivan
Jonathan Sullivan el 12 de Mzo. de 2012

0 votos

c=[8 0 5 0 1 0 4];
c_new = sort(c,'descend')

1 comentario

huda nawaf
huda nawaf el 12 de Mzo. de 2012
thanks,
now if have matrix
c=[3 4 1 0; 2 1 0 0];
how sort nonzero values?

Iniciar sesión para comentar.

Categorías

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by