我试图通过下面的代码来计算网络/用户的容量,但是我不断得到“下标索引必须是实数或逻辑”。
有人可以帮我吗?错误出在Throughput_(j)
部分。
%%%Parameters
B = 20*10^6;
No = 0.1e-15;
N = No*B;
Pstatic = 50; %% Fixed power in the circuit in Watt
fc = 2*10^9; %% carrier frequency
ht = 30; %% Transmitter height
hr = 2; %% Receiver height
AP = 2; %% Number of nodes
UE = 4; %% Number of users
这部分在网络设置中在节点和UE之间生成随机位置。
UserLocationX = randi(4, 1, 4);
UserLocationY = randi(4, 1, 4);
AccessPointX = randi(4, 1, 2);
AccessPointY = randi(4, 1, 2);
for p = 1:1:500; %% power allocation to users
for i = 1:AP;
for j = 1:UE;
此部分计算节点与用户之间的距离
compute_distance = pdist2([AccessPointX(:) AccessPointY(:)],[UserLocationX(:) UserLocationY(:)]);
计算网络节点与用户之间的路径损耗
C_Rx = 3.2*(log10(11.75*hrx))^2 - 4.97;
pathloss_compute = 69.55+26.16*log10(fc)-13.82*log10(ht)-C_Rx+(44.9-6.55*log10(ht))*log10(compute_distance);
%% Calculating the capacity.....Throws error here.
Throughput_(j) = B*log2(1 + p(j)*pathloss_compute/(p(j-1)*pathloss_compute + N));
end
end
end
答案 0 :(得分:1)
您正在尝试使用p
来索引(j-1)
,p
是一个只能用1进行索引的值。我猜您正在尝试做更多的事情这样。
Throughput_(j) = B.*log2(1 + p(j).*pathloss_compute./(p.*(j-1).*pathloss_compute + N));
快速说明,除非打算进行矩阵除法/乘法,否则请始终使用.*
或./
,而且,MATLAB中也不暗示乘法。它只是确保您的代码表现出预期的效果,并且是当您开始对代码进行矢量化时的良好做法。