Clear Filters
Clear Filters

Could anyone help me to overcome the error

1 view (last 30 days)
clear all
clc
%-----Simulation Parameters-----%
Bmax=2000000; %maximum available bandwidth for OFDMA
noise=1e-9; %fixed noise power is assumed
p_fix=0.01; %fixed transmit power is assumed
N_UE=[2 4 6 8 10];
N_SC=[12 14 16 18 20];
for it=1:2
for t= 1:length(N_UE)
%-----Topology-----%
Xmax=1; % x-coordinate for base station
Ymax=1; % y-coordinate for base station
radius=5; %coverage radius
xsd=ones(1,N_UE(t))*Xmax;
ysd=ones(1,N_UE(t))*Ymax;
rrx=radius*sqrt(rand(1,N_UE(t)));
thetarx=2*pi*rand(1,N_UE(t));
ang=0:0.01:2*pi;
xrx=xsd+rrx.*cos(thetarx); %random position of receivers-->x-coordinate
yrx=ysd+rrx.*sin(thetarx); %random position of receivers-->x-coordinate
th = 0:pi/100:2*pi;
xunit = radius * cos(th) + Xmax;
yunit = radius * sin(th) + Ymax;
% figure
% plot(xunit, yunit);
% hold on
% plot(ysd,xsd,'r^')
% hold on
% plot(yrx,xrx,'ko')
% hold on
%-----Subcarrier Correlation Matrix-----%
ratio=0.1; %Td over Tb: delay spread relative to OFDM frame duration
c=2*pi*ratio;
for r = 1:length(N_SC)
for j=1:N_UE(t)
temp=[];
for n=1:N_SC(r)
nc=(n-1)*c;
entry=(1+i*nc)/(1+nc^2);
temp=[temp entry];
end
Rchan=toeplitz(temp);
%autocorrelation matrix
[E,L]=eig(Rchan);
SQRTL=sqrt(L);
A=E*SQRTL/sqrt(2);
GG=randn(N_SC(r), 1)+i*randn(N_SC(r),1);
H=A*GG;
HH=abs(H);
% figure
% plot(abs(H))
% hold on
for k=1:N_SC(r)
F(j,k)=HH(k);
end
end
%-----Subcarrier Gain-----%
as=4;
bs=10;
Lsigma=as+(bs-as)*rand(1,N_UE(t));
Lshadow=10.^(randn(1,N_UE(t)).*(Lsigma/10));
ae=3;
be=5;
Lexp=ae+(be-ae)*rand(1,N_UE(t));
for k=1:N_SC(r)
for j=1:N_UE(t)
dist2(j)=sqrt((xrx(j)-xsd(j))^2+(yrx(j)-ysd(j))^2);
G(j,k)=(F(j,k)*Lshadow(j))/dist2(j).^Lexp(j);
end
end
%subcarrier allocation to users%
siz = size(G);
idx = sub2ind(siz, randi([1,N_UE(t)], 1, siz(2)), 1:siz(2));
C = zeros(siz);
C(idx) = G(idx);
D=sum(C,2);
% Throughput performance %
throughput =((Bmax.*log(1+((p_fix).*C))./noise));
overall_throughput = sum(sum(throughput));
output(t,r)=overall_throughput;
output_it(t,r,it)=output(t,r);
% figure
% plot(overall_throughput,'b','linewidth',2);
% legend(['No.of subcarriers=' num2str(N_SC(r))])
% xlabel('No of users')
% ylabel('overall_throughput')
% axis square
% grid on
end
end
end
out = sum(output_it,3);
final = out./2;
%Group formation%
N_G=5;%No of group
B = cell(N_G,1);
sumB = cell(N_G,1);
for d=1:1:N_G
if d==1
e=randi([2 5],1)% select No of UE randomly
else
sz=length(C(:,1));
e=randi([1 sz],1)% select No of UE randomly
end
idx=randsample(1:size(C,1),e)
B{d} = C(idx,:)
C(idx,:) = []
[rows, columns] = size(B{d});
% Get sum of columns and replicate vertically.
sumB{d} = repmat(sum(B{d},1), [rows, 1])
end
E=[sumB{1}; sumB{2};sumB{3};sumB{4};sumB{5}]
If i run this code i am getting Error using randi First input must be a positive scalar integer value IMAX, or two integer values [IMIN IMAX] with IMIN less than or equal to IMAX.
Error in model (line 113) e=randi([1 sz],1)% select No of UE randomly.
could anyone help me to overcome this error.

Answers (0)

Categories

Find more on Block and Blockset Authoring in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!