Cannot convert from cvx to double?

I don’t think there’s anything wrong with my sentence: E0(l,o)=c1pow_pos(norm(v_opt0(l,o)),3)+c2inv_pos(v_opt0(l,o));
But the system indicates that I “cannot convert from cvx to double”.
Can you help me modify the error, which bothers me a long time? Thank you very much!

Code:
o=1;
Omax=5;
eta0=zeros(Omax);
eta0(o)=0;

Vmax=100;
v0=zeros(2,Omax);
v0(:,o)=[0.1Vmax;0.5Vmax];

re00=zeros(2*U,1);
[re00(:,1),~,~,~]= get_group();

P=20:5:50;
for j=1:length(P)
Pmax=10^(P(j)/10);
[~,~,~,~,retP0,retP1,retP2,retP3]=getTotalgroup_ChangePmax();
pSolution0=retP0(:,j);

 %% 
while 1
cvx_begin 
        variable v_opt0(L,Omax)
        % expression E0(L,Omax)
        
         tempRate0=0;
         g0=0;
         R0=0;
           for l=1:L % 2
              for k=1:K  %12个不分组
                  pkn0=sum(pSolution0(((l-1)*K+k:(l-1)*K+K)));
                  tempRate0=tempRate0+log(alpha*(H.^2+re00((l-1)*K+k,1))+pkn0)/log(2);
                  
                  pkn00=sum(pSolution0(((l-1)*K+k+1:(l-1)*K+K)));
                  g0=g0+log(alpha*(H^2+re00((l-1)*K+k,1))+pkn00)/log(2);
                  
                  R0=R0+log(1+pSolution0((l-1)*K+k)/(alpha*(H.^2+re00((l-1)*K+k,1))+pkn00))/log(2);
              end        
           end       

              E0=zeros(L,Omax);

% for l=1:L
% E0(l,o)=c1pow_pos(norm(v_opt0(l,o)),3)+c2inv_pos(v_opt0(l,o));
E0(o)=c1pow_pos(norm(v_opt0(1,o)),3)+c2inv_pos(v_opt0(1,o));
E00(o)=c1pow_pos(norm(v_opt0(2,o)),3)+c2inv_pos(v_opt0(2,o));

% end
% E10=sum(E0(:,o));
E10=E0(o)+E00(o);

          f10=totWidth*tempRate0-eta0(o)*E10;
          gg0=g0;   
          M0=f10-gg0;

          maximize M0
          subject to

           g0 >= Rtarget;
           tempRate0 >= Rtarget;
           v_opt0(1,o)>=0;
           v_opt0(2,o)>=0;

cvx_end
    eta0(o+1)=R0/E10;  
    if abs(M0)>delta || o<Omax   
                o=o+1;           
    else
                y0(j)=R0;
                break; 
    end

Why did you comment out ```
expression E0(L,Omax)

See Cannot convert from cvx to double

I tried the expression, but the error also occurred. Then, I commented it out and turn to user

E0=zeros(L,Omax);

Obviously it doesn’t work either.

Keep
expression E0(L,Omax)

and remove
E0=zeros(L,Omax);

That statement (which you should remove, overrides (supersedes) the expression declaration. So by the time you use E0, it’s as though you never made the expression declaration.

Also note that all elements of CVX expressions are initialized to zero, so there is not need to explicitly initialize any expression elements to zero.

I have modify it with

expression E0(L,Omax).

But the error also occurred.
I find this statement maybe occurred error in “The reason this occurs is that the Matlab variable x is initialized as a numeric array when the assignment x(1)=1 is made; and Matlab will not permit CVX objects to be subsequently inserted into numeric arrays.”

But I don’t know how to modify it.

Code:
cvx_begin
variable v_opt0(L,Omax)
expression E0(L,Omax)

      for l=1:L                       
            E0(l,o)=c1*pow_pos(norm(v_opt0(l,o)),3)+c2*inv_pos(v_opt0(l,o));
      end   
      E10=sum(E0(:,o));

cvx_end

Does this code generate that error message? Presuming you re showing the entirety of the code, I don’t see why it would. I.e., I am presuming that you do not still have E0=zeros(L,Omax) in the code.