Why the results are different

cvx_clear    
cvx_begin quiet 
cvx_solver mosek
variable X(N,K) binary
expression WPT(1,N)
expression trans(K)
maximize sum(sum(X.*S))           % maximize sum(trans)
subject to:
    WPT(1,1)=0;
     for m=2:N
         WPT(1,m)=WPT(1,m-1)+1*delta_t*R2(1,m);
         Ef(1,m)-WPT(1,m)<=E0; 
     end
    for k=1:K
        trans(k)=0;
        for m=1:N
            trans(k)=trans(k)+X(m,k)*S(m,k);
        end
        trans(k)>=D(k);
    end
    for m=1:N
        sum(X(m,:))<=1;
    end
cvx_end

*maximize sum(sum(X.S)) and maximize sum(trans) have different results

You have to assign expressions, such as trans, before they are used. Otherwise, they will have their initial (default) value of zero. So your alternate objective of maximize sum(trans) is just maximizing zero, i.e., is only a feasibility problem.

Additionally, there is no guarantee in CVX that the numerically populated values of expressions after CVX completion will correspond to their optimal values (even though the optimization was performed correctly). For that, you need to reevaluate expressions after CVX completion, starting from the values of CVX variables, and not expressions.

Thank you very much!