# Using double incorrectly. Cannot convert from cvx to double

There are my codes:

o=1;
Omax=5;
elta3(o)=0.1;
tempRate=zeros(48,Omax);
f=zeros(Omax);
M3=zeros(Omax);

while 1
cvx_begin
variable p_opt3(48,Omax)
expression tempRate(48,Omax)
% expression f3(48,Omax)
% expression M(Omax)

% calculate f3
for k=1:K  %12
for wn=1:WN  % WN=2
for n=1:N     % N=2
pkn=sum(p_opt3((k-1)*N+1:(k-1)*N+n,o));
end
tempRate((k-1)*WN+wn,o)=log(alpha*(H^2+re33((k-1)*WN+wn,1))+pkn)/log(2);
%  f3((k-1)*WN+wn,o)=sum(tempRate(1:(k-1)*WN+wn,o));
end
end
f3(o)=sum(tempRate(:,o));

M3(o)=f3(o)-elta3(o);

cvx_end
o=o+1;
[M3(o),~,~]=calcMaxVal_group3(K,N,L,WN,p3,H,re33,v,c1,c2,alpha);
if abs(M3(o)-M3(o-1))<delta && o<Omax
break;
else
end

I don’t know why the f3 can’t be assigned to M3. The wrong is " Using double incorrectly. Cannot convert from cvx to double".

And when I call/invoke this file from another file (the contents are similar, include statements and parameters), it displays “tempRate((k-1)WN+wn,o)=log(alpha(H^2+re33((k-1)*WN+wn,1))+pkn)/log(2);” is wrong.The wrong is " Index out of matrix dimension". But I run this file alone, it is right.

Here are another files’ codes:

v2(:,o)=[0.1Vmax;0.5Vmax];
tempRate=zeros(48,Omax);
pSolution2=zeros(2U,Omax); %功率值
[pSolution2(:,o)]=getgroup2_p();
re22=zeros(2
U,1);
[~,re22(:,1),~]= get_group();
while 1
cvx_begin
variable v_opt2(L);
expression tempRate(2U,Omax)
expression f2(2
U,Omax)

% cla f2
for k=1:K
for wn=1:WN
for n=1:N
pkn=sum(pSolution2((k-1)*N+1:(l-1)*K*N+(k-1)*N+n));
end
tempRate((k-1)*WN+wn,o)=log(alpha*(H^2+re22((k-1)*WN+wn))+pkn)/log(2);
f2((k-1)*WN+wn,o)=sum(tempRate(1:(k-1)*WN+wn,o));
end
end
end

This is usually the result of assigning a CVX variable or expression to an element(s) of an array without having declared the array as an expression. You don’t need to (but can) declare the array if you assign the whole array all at once. E.g. A = B*C, where B is a CVX variable and C is a double precision matrix creates the expression A all at once; so A does not need to be declared as an expression. But if you assign elements of A (index into A) without having declared it as an expression of the appropriate dimensions, you might get this error. For example, A(3,:) = x.

I see you declared some expressions. But I think you also need to declare f3 as an expression before you use it. That’s why you got the error. I will let you determine whatever other similar fixes are needed to your programs.

CVX Users’ Guide section on Assignment and expression holders