Problem writing binary code

I tried to write the code using Salver Mosek, but I didn’t succeed. Can anyone help me?
UT=[1 3 2 1];
DT=[4 2 2 2];

Show us what you tried, and what didn’t succeed. There are many posts on which show how to use binary variables for various purposes in optimization problems

My problem is with intervals, for example,in Eq18 how to model sum from t - t+DT-1 for every moment ?
i have to use loop “for”?

                    cvx_solver Mosek 
                    variable u_on(T,4) binary
                    variable u(T,4) binary
                  variable u_off(T,4) binary
minimize ...
subject to
 for t=1:T

is it correct?
I think the code is dirty, how can i rewrite it with this manner i don;t have to use loop

You need to have another level of for loop over j. and change u_on(t,2) to u_on(t,j) and change uu(t,1) to u_off(t,j).

Perhaps some for loops could be eliminated,with vectorization. That’s not necessary, but would speed up CVX processing of the constraints.

I’ll let you check this, and work out the rest of the details.