Trying to minimize the following cost function:

```
for n=1:20
minimize ((sum((max(cumsum((reshape (((reshape(squeeze(u(n,:,:)), [],1)).*r), n2, T))))))*C1)+(sum((max(cumsum((reshape (((reshape(squeeze(u(n,:,:)), [],1)).*t), n2, T))))))*C2);
end
```

In my code I’ve kept the cost function within a for loop. The reason I did this way is to avoid the error “Invalid constraint: {real affine} == {convex}”. In the above code r and t are binary variables declared under CVX as r (n2,T) & t (n2,T) . C1 & C2 are constants.

The error is as below:

An objective has already been supplied for this problem.

Can anyone help me to resolve it?