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

 采纳的回答

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

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

1 个评论

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