binary is used to constrain a variable to be binary.

Syntax

F = binary(x)

Examples

Setting up a binary linear program {min cTx subject to Ax≤b} can be done as

x = binvar(n,1);
solvesdp(A*x<b,c'*x)

or

x = sdpvar(n,1);
solvesdp([A*x<=b, binary(x)],c'*x)

The binary constraint is imposed on the involved variables, not the actual sdpvar object. Hence, the following two constraints are equivalent

F = binary(x);
F = binary(pi+sqrt(2)*x);

Comment

If possible, use binvar instead.

Related commands

intvar, binvar, integer, sdpvar