Matlab code to find network capacity throws error
Show older comments
I am trying to calculate network/users' capacity through the code below but I constantly get "Subscript indices must either be real positive integers or logicals". I have almost spent a decade finding solution to it without success. The error is at the Throughput_(j) part.
%%%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
%%Calculating location between nodes and UEs
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(:)]);
%%%Calculating the pathloss
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.....Error throws up here!!! "Subscript indices must either be real positive integers or logicals".
Throughput_(j) = B*log2(1 + p(j)*pathloss_compute/(p(j-1)*pathloss_compute + N));
end
end
end
Answers (1)
Image Analyst
on 22 Jul 2018
Since you didn't supply hrx, we can't run your code to reproduce the error.
You can look at the FAQ: https://matlab.wikia.com/wiki/FAQ#How_do_I_fix_the_error_.22Subscript_indices_must_either_be_real_positive_integers_or_logicals..22.3F
In the line
Throughput_(j) = B*log2(1 + p(j)*pathloss_compute/(p(j-1)*pathloss_compute + N));
you have j-1. Well, the first j is 1, so j-1 is zero. There is no zeroeth element of an array. I suggest you rethink what your algorithm is trying to do.
Categories
Find more on Standard File Formats in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!