Defining a constraint in a function

Maybe you can have a function return a string specifying the constraint, then eval the string in your main program. Or eval(my_constraint_function(...)) .

There are posts of mine on this forum that do some kind of string eval thing in CVX. Building Functions using CVX - #6 by Mark_L_Stone and Building Functions using CVX - #9 by Mark_L_Stone .

Also look at other posts from Search results for 'eval string' - CVX Forum: a community-driven support forum

Whether any of that is useful to you is another matter.