I want to change the for loop to speed up my code

조회 수: 1 (최근 30일)
Matthew Worker
Matthew Worker 2021년 6월 6일
댓글: Rena Berman 2021년 12월 16일
clc;
clear;
M=60;
N=(linspace(6,10,5)).^2; %Number of Elements IRS
K=linspace(4,10,7); %Number of Single Antennas UE
L = 3; %Number of paths
fc = 28e9; %Carrier freq
SNR = -10; %Signal to Noise Ratio
Pt = 1; %Total Power
Pn = Pt/(10^(SNR/10)) ; %Noise Power
C_T = zeros(5,7);
Max_iter = 1000;
for iter = 1:Max_iter
for n = N
%% Millimeter wave Channel
G = M_Wave_channel_Matrix(fc, M, n, L, 'BS', 'IRS'); %NxM
%% Diagonal Matrix for the response of the RIS elements
x = rand(1,n);
theta = (2*pi)*x; %Reflecting Angle IRS
Phi = diag(exp(1i*theta)); %phase shift Matrix for IRS, % Set Amp = 1
%% channel IRS-UE
for k = K
F=zeros(k,n);
H=zeros(k,M);
for i=1:k
fk = M_Wave_channel_Matrix(fc, n, 1, L, 'IRS', 'UE'); %1xN
F(i,:)=fk; %KxN
%% channel BS-UE
hk = M_Wave_channel_Matrix(fc, M, 1, L, 'BS', 'UE'); %1xM
H(i,:)=hk; %KxN
end
HT = H+F*Phi*G; %Channel Matrix
W = pinv(HT); %Precoding Matrix
W_bar = W./vecnorm(W,2,1); %Normalized
D_Matrix = HT*W_bar; %Diagonal Matrix
D_Square = (abs(diag(D_Matrix))').^2; % Channel gains
R = D_Square/Pn;
C = log2(1+R); %Capacity
C_T(N==n,k==K) = C_T(N==n,k==K) + 1/Max_iter*sum(C); %Total Capacity
end
end
end

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 6월 6일
You should correct these for loops, e.g:
for n = N % Err. Fix or remove it
end
...
for k = K % Fix or remove it
end

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by