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

 채택된 답변

Honglei Chen
Honglei Chen 2012년 3월 12일

0 개 추천

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));

추가 답변 (1개)

Jonathan Sullivan
Jonathan Sullivan 2012년 3월 12일

0 개 추천

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

댓글 수: 1

huda nawaf
huda nawaf 2012년 3월 12일
thanks,
now if have matrix
c=[3 4 1 0; 2 1 0 0];
how sort nonzero values?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File 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