Info

此问题已关闭。 请重新打开它进行编辑或回答。

Could anyone help me to solve the issue of the size of the matrix

1 次查看(过去 30 天)
If i run the following code
clc
clear all
%-----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=[10 20 30 40 50];
N_SC=[60 70 80 90 100];
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 without Grouping %
%----------------------------------------------------------------------
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
%----------------------------------------------------------------------
% %Group formation%
%----------------------------------------------------------------------
N_G=4;%No of group
B = cell(N_G,1);
sumB = cell(N_G,1);
for d=1:1:N_G
if d==N_G
sz=length(C(:,1));
e=sz;
else
if d==1
e=randi([2 5]);% select No of UE randomly
else
sz=length(C(:,1));
sz=ceil(sz/2);
e=randi([1 sz]);% select No of UE randomly
end
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}];
%----------------------------------------------------------------------
% % Throughput performance with grouping%
%----------------------------------------------------------------------
throughput_E =((Bmax.*log(1+((p_fix).*E))./ noise));
overall_throughput_E = sum(sum(throughput));
output_E(t,r)=overall_throughput_E;
output_E_it(t,r,it)=output_E(t,r);
end
end
end
out = sum(output_it,3);
final = out./2;
out_E = sum(output_E_it,3);
final_E = out_E./2;
It executes but the size of the C in line 80 should be (50*100) but when the code executes it was (0*100).Please help me to solve this issue.
  2 个评论
John D'Errico
John D'Errico 2017-12-23
Will you please stop asking the identical question multiple times? You asked this question twice. That is one reason you have asked now 117 questions, Almost all of them have been asked at least twice.

回答(1 个)

Walter Roberson
Walter Roberson 2017-12-23
At line 80, on the first pass through, C has not yet been defined at all, so you cannot say that it is empty -- it simply does not exist until line 80 has been executed once.
After each time you assign zeros to C on line 80, on line 122, you randomly delete rows out of C, and your code in that section is designed in such a way that you will always delete all of the rows. After the for d=1:1:N_G loop has completely executed, C will have been completely emptied.
It is that completely empty version of C that will exist the second (and subsequent) times you reach line 80; then at line 80 you write new zeros into C to repopulate it again.
  10 个评论

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by