フィルターのクリア

Unable to perform assignment because the left and right sides have a different number of elements.

1 回表示 (過去 30 日間)
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)
gamma = 2×1
0 0
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
e = 2×1
0.2882 2.6803
Unable to perform assignment because the left and right sides have a different number of elements.
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

採用された回答

Image Analyst
Image Analyst 2023 年 6 月 25 日
編集済み: Image Analyst 2023 年 6 月 25 日
In
gamma(i)=(f(r,p,Mt,SNR,e));
f returns a variable Wp, which is a vector of MT elements. How are you thinking that you're going to stick it in the single, i'th element of gamma? Also, gamma is a built in function so don't use it as the name of your variable. Call it theGamma or something. Maybe theGamma should be a 2-D matrix with Mt columns
theGamma = zeros(1, Mt) % Call this BEFORE the loops start.
and then you can fill up the whole row
Wp = f(r,p,Mt,SNR,e); % A 1 x Mt row vector.
theGamma(i, :)= Wp; % Stuff Wp into the i'th row of theGamma
Also, see the FAQ for a discussion of the error:

その他の回答 (1 件)

Parag Jhunjhunwala
Parag Jhunjhunwala 2023 年 6 月 25 日

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by