can i sort a vector in cvx

If the vector is a CVX variable, then in general, no, as full sorting is non-convex.

However, if X is a CVX variable, then min(X) is convex, max(X) is concave. And you can use these in CVX if you follow the DCP rules. You can also use lambda_sum_largest, lambda_max, lambda_sum_smallest, and lambda_min for eigenvalues.

Not sure what you mean, but you can do x1 <= x2 <= x3, so the elements of x is sorted.

Good point Erling. I guess we’re all confused what the OP wants to do.

i have a vector that is variable from VCX for example it is 1 0 1 0 1, i get from it another vector contains the index of the number if it is one so the vector will be 1 0 3 0 5…what i need to sort these vectors or to get only the non zeros values .when i use sum largest in order to get the maximum which is 5, after that i will get the sum of largest 2 which are 3+5 will be, i though i will save the value 5 and then subtract 8-5 to get 3 and so on but cvx told me you can’t make convex-convex as the result of sumlargest is convex… so if there is any solution to sort a vector or subtract 2 convex or to remove zeros…??

I think we’re back to where we were in Removing zeros from vector . If there is any hope of doing what you want in CVX, you’ll have to figure out how to do it making use of integer or binary variables in an MIDCP compliant manner.