Unable to perform assignment because the left and right sides have a different number of elements.
Mostrar comentarios más antiguos
Hello
I try to collect results of function in a vector, but there is error "Unable to perform assignment because the left and right sides have a different number of elements".
I tried also use "reshape (f,[],1), but it doesn't help.
Mr=2;
Mt=2;
Rt=eye(Mr);
Rr=[1 08;0.8 1];
K=0;
Hw=(randn(Mr,Mt)+1i*randn(Mr,Mt))./sqrt(2);
H=sqrt(1/(K+1))*sqrtm(Rr)*Hw*sqrtm(Rt');
N=1000;
gamma=zeros(Mt,1)
for SNR=0:1:15
for k=1:1:N
Hw=(randn(Mr,Mt)+1i*randn(Mr,Mt))./sqrt(2);
X = Hw*Hw';
r=rank(X);
e = eig(X)
for i=1:r
p=1;
gamma(i)=(f(r,p,Mt,SNR,e));
Cclosed=sum(log2(1+SNR*gamma(i)/Mt*e(i)));
end
R(k)=Cclosed;
end
stem(SNR,mean(R))
xlabel("SNR [dB]");
ylabel("Ergodic Capacity [bits/s/Hz]");
hold on;
end
function Wp=f(r,p,Mt,SNR,e)
for i=1:1:r-(p-1)
wl=1/(r-(p-1))*(Mt+Mt/SNR*sum(1/e(i)));
end
for i=1:1:Mt
Wp(i)=wl-(Mt/SNR*1/e(i));
if Wp(i)<=0
Wp(i)=[];
end
if sum(Wp)~=Mt
p=p+1;
else end
end
end
Respuesta aceptada
Más respuestas (1)
Parag Jhunjhunwala
el 25 de Jun. de 2023
0 votos
This question has already been answered here:
Categorías
Más información sobre Lengths and Angles en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!