If statement error

hi, I’m having a problem with an if statement

if (norm(Ex(:,k) - c_pos(:,k))-2)<=0
d=0;
else d=(norm(E
x(:,k) - c_pos(:,k))-2);

It appears that
“The following error occurred converting from cvxcnst to logical:
Disciplined convex programming error:
Constraints may not appear in if/then statements.”

How can i do it without having this issue. Ty

You need to use Big M approach using binary variables using CVX’s MIDCP capability. Search on this forum for relevant posts. You can read chapter 9 of https://docs.mosek.com/MOSEKModelingCookbook-letter.pdf and also read https://www.artelys.com/uploads/pdfs/Xpress/mipformref-1.pdf .

Did you solve it? I have the same problem.

if you have the same problem, the same links apply to you.