Cvx real affine expression (1x2x2 array) Error using cvx_end (line 267) Your objective function is not a scalar

Hello All,
I have that error: “Your objectşve function is not scalar” But I could not find where I am wrong. This is my code can you look at it?
function G = TD_P_inv_Dual(P_exp,B,A_ax,B_by)

d = size(P_exp,1); %dimentions
m = size(P_exp,3); %number of operators
cvx_begin
variable S(1,m,m) %For the dual we have not dual variables instead of that we have variable and in this equation we have S
W_hat=zeros(d^2,d^2);
%variable sigma_e(d^2,d^2,d) hermitian semidefinite 
for a=1:d
    for b=1:d
        for x=1:m
            for y=1:m
                W_hat=W_hat+B(a,b,x,y).*(kron(A_ax(:,:,x,a),B_by(:,:,y,b)));  
            end
        end
    end
end
W=sum(sum(sum(sum(B.*P_exp))));


J=cvx(0);
J= (S*W);
J=real(J) 
minimize(J)

subject to

for e=1:d

(W_hat-kron(squeeze(A_ax(:,:,1,e)),eye(d)))==semidefinite(d^2,d^2);
end

cvx_end

G=double(J);

Bets!

You haven’t shown us the dimensions of W. If m > 1, I don’t think there are any dimensions of W which would make S*W a scalar. Therefore, J will not be a scalar, hence the error message. Based on " Cvx real affine expression (1x2x2 array)" appearing in the title of your question, I presume J evaluates to 1 by 2 by 2, which is not a scalar, which it needs to be in order to be used as the objective.

Also, you calculate W_hat but don’t use it, at least in the code that is shown.

Thanks

it needs to be in order to be used as the objective.
What does it mean? How can I use J as an objective? Can you please write me this code line?

Also, you calculate W_hat but don’t use it, at least in the code that is shown.
Later I saw and did a correction for this line

The objective must evaluate to a real scalar. It is your optimization problem, so hopefully you know what that real scalar objective function is supposed to be; it can’t be J, because it is not a scalar. I don’t know what objective function you are trying to minimize.

I got your mean thanks a lot I just forgat to thisnk for S