var_y is a vector with dim (NumVar,1)

matrix_a is a matrix with dim (NumKey,NumVar)

each of vec_1, vec_2, vec_3 and vec_4 is a vector with dim (NumKey,1)

cvx_begin

variable var_x(NumVar,1)

minimize( norm(var_x - var_y) )

%

subject to

-ones(NumVar,1) <= var_x <= ones(NumVar,1)

0.99 <= sum(max(var_x,0)) <= 1.01

0.99 <= sum(max(-var_x,0))<= 1.01

vec_1 <= matrix_a * max(var_x,0) <= vec_2

vec_3 <= matrix_a * max(-var_x,0) <= vec_4

cvx_end

Many thanks!