```
Optimization variables can't be used in 'if' statements, but I need to make judgments
about optimized variables. How to achieve this function?
Thanks.
N = 10;
Kr = 3;
h = rand(Kr,N)+1i*rand(Kr,N);
H = zeros(N,N,Kr);
for k = 1:Kr
H(:,:,k) = h(k,:)'*h(k,:);
end
cvx_begin
cvx_quiet(true);
variable W(N,N,Kr) complex;
minimize real(trace(sum(W,3)))
subject to
for k = 1:Kr
if real(trace(H(1:8,1:8,k)*W(1:8,1:8,k)))>1e-4 %Disciplined convex programming error:
% Constraints may not appear in if/then statements.
real(trace(H(9:10,9:10,k)*W(9:10,9:10,k)))<=1e-4;
end
end
cvx_end
```

# How to achieve this function?

**CCleaner**(hataimengzhu) #1

**Mark_L_Stone**(Mark L. Stone) #2

Presuming you have suitable bounds available, I think you should be able to do this using binary variable, i.e., MIDCP.

**Mark_L_Stone**(Mark L. Stone) #4