MATLAB: How to swap row elements by increasing and decresing order.

mathematicsMATLAB

p = [30 30 30 30 30 30 0 0 0 0 0 0 0 0 30 30 30 30 30 30]
I want to swap it like [30 30 30 30 30 30 30 30 30 30 30 30 0 0 0 0 0 0 0 0];
Np = length(M);
for p = Np/2: -1:2
for CP = p-1:-1:1
if M(1,CP) ~= M(1,CP+1)
M(1,CP) = M(1,CP+1)
end
end
end

Best Answer

sort(p, 'descending')