Having error with variable

Dear all
i have a cvx problem and variable w(L,K)
.when i run it I have this error
Error using .* (line 46)
Matrix dimensions must agree.

Error in (line 6)
I=h(:,k)’.* w(:,i).*w(:,i)’.*h(:,k)+I;

i don’t know why w can not be multiplied with h . i check the dimensions but it is ok . i think there is a problem with w definition. could you please help me. it is so urgent for me.
regards

Please provide a full reproducible example. No one can diagnose your problem without more information. Your code looks rather suspicious, though, unless L = 1, for instance.

Hint: if you replace all CVX variables by populated (numerical) MATLAB variables of the same dimensions, any expressions in your code need to be conformal (compatible dimensions), and if not, your code is in error and can’t possibly work when CVX variables are used.

thanks a lot .here is my complete code
% initialization optimization for W0 and U0
clc;
close all
load ‘initial-w’
load ‘initial-u’
epsilon=0.0001;
L=10;
K=10;
N=1;
for k=1:K
for l=1:L
p=[zeros(1,(l-1)*N),ones(1,N),zeros(1,(L-l)*N)];
ro(l,k)=1./(trace(w(:,k).*w(:,k)’.diag§)+epsilon);
end
end
r_old=r;
ro_old=ro;
u_old=u;
w_old=w;
for itr=1:1000
cvx_begin
variable w(L,K)
variable u(L,K)
% %
H=0;
for k=1:K
I=0;
for i=1:K
I=h(:,k)’.
w(:,i).*w(:,i)’.*h(:,k)+I;
end
H=H+ log2(sigma.^2+I);
end
% %
f2=0;
for l=1:L
for k=1:K
p=[zeros(1,(l-1)*N),ones(1,N),zeros(1,(L-l)*N)];
f2= f2+ ro_old(l,k)*trace(w(:,k).w(:,k)’. diag§)*r_old(k);

 end

f3(l)=f2;
end
f4=0;
for l=1:L
for k=1:K
p=[zeros(1,(l-1)*N),ones(1,N),zeros(1,(L-l)*N)];
f4= f4+ ro_old(l,k)*trace(w(:,k).w(:,k)’. diag§);

 end

f5(l)=f4;
end
for l=1:L
x2=cvx(0);
y2=cvx(0);
for ll=1:L
if ll~=l
x2=z+G(l,:).*u(:,l).*u(:,l)’.*G(l,:)’+x2;
y2=z+G(l,:).*u(:,l).*u(:,l)’.*G(l,:)’+y2;
end
end
phi(l)=-DC2(x2,y2);
end

for l=1:L

r2=0;
for j=1:L
    r2=r2+G(l,:).*u(:,l).*u(:,l)'.*G(l,:)';
end
f(l)=f3(l)-log2(det(z+r2))  ;

end
% %
for k=1:K
s1=0;
s2=0;
for i=1:K
if i~=k
s1=s1+ h(:,k).*w(:,k).*w(:,k)’*h(:,k)’;
s2=s2+ h(:,k)*w_old(:,k).*w_old(:,k)’.*h(:,:,k)’;
end
end
g(k)=DC1(sigma^2+s1,sigma^2+s2);

end
max sum(h)-sum(g)
subject to
for l=1:L
f(l)+phi(l)<=0;
end
sum(f5)<=1
cvx_end
r_old=r;
ro_old=ro;
u_old=u;
end

now could you please tell me where is wrong?

sorry nut i can’t understand your hint.could you please explain more?

I don’t know what the dimensions of h are, but given that L is not 1(it equals 10),`

h(:,k)’.*w(:,i).*w(:,i)’.*h(:,k)
can not be conformal (dimensionally consistent). Given that you apparently use the resulting I as a scalar, I am guessing that what you want is

h(:,k)’*w(:,i)*w(:,i)’*h(:,k)

However, in order to avoid a CVV error, parentheses (or use of an intermediate expression) are needed to separate w(:,i) and w(:,i)' and prevent them from being directly multiplied.

So, the following line of code should work

I=(h(:,k)’*w(:,i))*(w(:,i)’*h(:,k))+I;

but I don’t know whether this is what you really want.

I haven’t checked any of the rest of your code.

What I mean by my hint, is that if instead of declaring variable W(L,K) you created an L by K numerical matrix in MATLAB, then the line of code needs to be able to execute in MATLAB without error message due to incompatible dimensions. If dimensions are incompatible, it won’t work when w is a CVX variable or expression. If dimensions are consistent, then CVX rules also need to be followed. So dimensional consistency is necessary but not sufficient for acceptance by CVX.