I want to put this constraint in CVX.

\frac{q_n}{d_n}\sum_{m=1}^{M} z_{n,m} - \frac{q_{n-1}}{d_{n-1}}\sum_{m=1}^{M} z_{n-1,m} \geq 0 , \quad \forall n\in 2,\dots,N.

Here z is defined as

```
variable z(N,M) binary
```

Here, q_n and d_n, n=1,2,\cdots, N are known parameters.

Just “form” the LHS using `sum(z(n or n-1,:))`

the same way you would if all the variables were numerical MATLAB variables. It is straightforward to do this inside a for loop from 2 to N. Perhaps there is a vectorized way to do this without using a for loop, but that is not necessary, except perhaps for execution speed.