CVX vs fmincon for sum of exponentials

You can build up CVX expressions in for loops, the same way your anonymous function code does, except, of course, X is declared as a symmetric variable for each of n slices, as shown in mcg’s answer at Cvx sdp mode and cell arrays. I.e., variable X(2,2,n) symmetric. After the for loop, f can be your objective function.