MATLAB: How sort just nonzero values

sort

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

Best Answer

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