The Average of the Matrix G with the dimension (M,n) that I'm repeating 3 times in a loop so I'll have 3 matrices of G (M,n) and I want to take the Average of these 3 matrices so I can get only one matrix of G(M,n) represent the Average of them)

2 次查看(过去 30 天)
clc; clear;
M=5; n=3; freq = 28e9; lambda = physconst('LightSpeed')/freq; d_BS=lambda/2; %Inter-antenna separation atthe BS. d_IRS=lambda/2; %Inter-element separation at the IRS.
G = zeros(M,n);
for l=1:3
theta_2=-pi+(2*pi*rand); %AoA [-pi,pi]
phi_2=(-pi+(2*pi*rand))/2; %AoA [-pi/2,pi/2]
theta_1=-pi+(2*pi*rand); %AoD [-pi,pi]
phi_1=(-pi+(2*pi*rand))/2; %AoD [-pi/2,pi/2]
for mi=1:M
for ni=1:n
e = exp(1i*2*pi/lambda*((mi-1)*d_BS*sin(theta_1)*sin(phi_1)+(ni-1)*d_IRS*sin(theta_2)*sin(phi_2)));
Beta = 1; % path loss factor
G(mi,ni) = 1/sqrt(2).*sqrt(Beta).*e
end
end
end

采纳的回答

DGM
DGM 2021-5-17
编辑:DGM 2021-5-17
Something like this
M=5;
n=3;
freq = 28e9;
lambda = physconst('LightSpeed')/freq;
d_BS=lambda/2; %Inter-antenna separation atthe BS.
d_IRS=lambda/2; %Inter-element separation at the IRS.
G = zeros(M,n,3); % allocate big enough for all copies
for l=1:3
theta_2=-pi+(2*pi*rand); %AoA [-pi,pi]
phi_2=(-pi+(2*pi*rand))/2; %AoA [-pi/2,pi/2]
theta_1=-pi+(2*pi*rand); %AoD [-pi,pi]
phi_1=(-pi+(2*pi*rand))/2; %AoD [-pi/2,pi/2]
for mi=1:M
for ni=1:n
e = exp(1i*2*pi/lambda*((mi-1)*d_BS*sin(theta_1)*sin(phi_1)+(ni-1)*d_IRS*sin(theta_2)*sin(phi_2)));
Beta = 1; % path loss factor
G(mi,ni,l) = 1/sqrt(2).*sqrt(Beta).*e; % write just this page
end
end
end
G = mean(G,3) % average along dim3

更多回答(1 个)

Sulaymon Eshkabilov
in your exercise, the loop is not a good one. You can use vectorization instead. E.g.:
theta_2=-pi+(2*pi*rand(3,1)); %AoA [-pi,pi]
phi_2=(-pi+(2*pi*rand(3,1)))/2; %AoA [-pi/2,pi/2]
theta_1=-pi+(2*pi*rand(3,1)); %AoD [-pi,pi]
phi_1=(-pi+(2*pi*rand(3,1)))/2; %AoD [-pi/2,pi/2]
M_theta2=mean(theta_2);
M_phi2=mean(phi_2);
M_theta1=mean(theta_1);
M_phi1=mean(phi_1);

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by