i want to store a 100 x 100 matrix in hi_i for each iteration of irs1 and irs 2 when my sij1*sij2' is of 100x100 multiplied by a scalar in h_i.

2 Ansichten (letzte 30 Tage)
L=12; % IRS
element=10;
lambda=0.06;
l=lambda/2;
%% channel between IRS and IRS
rr=11;
for irs1 = 1:(L-1) % IRS1
thetaa=2*pi*rand(rr) ;
thetae=2*pi*rand(rr) ;
phi_a=2*pi*rand(rr) ;
phi_e=2*pi*rand(rr) ;
ij=1;
for irs2 = (irs1+1):L % IRS2
%% AoA arrival
sij2=array_resp(10,phi_a(ij),phi_e(ij)); %100x1
sij1=array_resp(10,thetaa(ij),thetae(ij)); %100x1
hi_i(irs1,irs2)=(sqrt(alpha)/di_i(irs1,irs2))*(exp(-1j*(2*pi*di_i(irs1,irs2)/lambda)))*sij2*sij1'; %% distance between the IRSs
hi_i(irs2,irs1)=hi_i(irs1,irs2);
ij=ij+1;
end
rr=rr-1;
end
  3 Kommentare
Arif Hoq
Arif Hoq am 18 Feb. 2022
you can use 'cell array' to store your iteration value. what is the function:array_resp. if you have the code of this function please paste here
Maimoona Asad
Maimoona Asad am 18 Feb. 2022
function array=array_resp(N,theta_a,theta_e)
lambda=0.06;
l=lambda/4;
s_v1=[];
for nn=0:N-1
h_d1=exp(-1j*pi*(nn)*((2*l)/lambda)*sin(theta_e)*cos(theta_a));
s_v1=[s_v1 h_d1];
end
sv_1=(s_v1)';
s_v2=[];
for nn=0:N-1
h_d2=exp(-1j*pi*(nn)*((2*l)/lambda)*cos(theta_e));
s_v2=[s_v2 h_d2];
end
sv_2=(s_v2)';
array=kron(sv_1,sv_2);

Melden Sie sich an, um zu kommentieren.

Antworten (1)

KSSV
KSSV am 18 Feb. 2022
WE cannot correct your code as some variables are not defined. But still, your error is simple. You are trying to store a 100x100 matrix at a single element which you cannot.
% Demo
A = zeros(3) ; % 3x3 matrix intilaized
A(1,1) = rand ; % a single element saved no error
A(1,:) = rand(1,3) ; % three elements stored at three places no error
A(3,3) = rand(3) ; % error, you cannot store 3x3 matrix at a single element
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 3-by-3.
S the work around is, initiate the initial matrix properly and use correct indexing.
If no store the matrices into a cell .
A = cell(2,2) ;
A{1,1} = rand(3) ;
A{1,2} = rand(4) ;
  3 Kommentare
Maimoona Asad
Maimoona Asad am 18 Feb. 2022
clc
clear all
close all
clc
clear all
close all
L=12; % IRS
element=10;
lambda=0.06;
l=lambda/2;
Sigma=db2pow(-90); %% -60dbm
a_db=-46;
alpha=db2pow(a_db);
K=4; % Number of users
radius=15;
X0=0; % x-coordinate of Centre of the circle
Y0=0; % y-coordinate of Centre of circle
%% Base stations
x_b=[0.7298; 3; -5.23; 11.86]; % x coordinates of base station
y_b=[12.48; -1.497; -6.139; -3.23]; %y coordiantes of base station
%% IRSs placement
X3=[-7.655; -6.189; -3.251; 2.926; 6.534; 10.79; 5.203; -4.465; 1.42; -8.66; -0.8748; 6.534] ;
Y3=[1.393; 10.42; 6.639; 5.821; 8.425; 2.924; 1.139; 0.7508; -7.917; -6.928; -10.01; -7.03];
p=0;
%% loop for the elements of irs
N=100:100:500; %% number of elements in an IRS
NN = length(N) ;
for n = 1:length(N)
nn=N(n);
for i=1:L
for j=1:element
for k=1:(nn)/(10)
x3(j,k,i) = X3(i,1) + p;
y3(j,k,i) = Y3(i,1);
p=k*l; % Each time lambda is added to the x-coordinate
x_e(j,k,i,n) = x3(j,k,i); % X coordinate of an element of IRS for plotting
y_e(j,k,i,n)= y3(j,k,i); % Y coordinate of an element of IRS for plotting
end
p=0;
Y3(i,1) = Y3(i,1) + l;
end
% plot(x3,y3,'bo','HandleVisibility','off')
end
end
%% Distances between the IRSs
for irs1 = 1:(L-1) % IRS1
for irs2 = (irs1+1):L % IRS2
di_i(irs1,irs2)=sqrt((X3(irs2)-X3(irs1))^2+(Y3(irs2)-Y3(irs1))^2); %% distance between the IRSs
di_i(irs2,irs1)=di_i(irs1,irs2);
end
end
%% Distances between the BS and IRSs
for bs = 1:4 % IRS1
for irs = 1:L % IRS2
db_i(bs,irs)=sqrt((X3(irs)-x_b(bs))^2+(Y3(irs)-y_b(bs))^2); %% distance between bs and IRSs
db_i(irs,bs)=db_i(bs,irs);
end
end
%% channel between BS and IRS
for bs = 1:4 % IRS1
phi_a=2*pi*rand(L) ;
phi_e=2*pi*rand(L) ;
for irs = 1:L % IRS2
ai_b=array_resp(10,phi_a(irs),phi_e(irs)); %steering vector1
hb_i(bs,irs)=(sqrt(alpha)/db_i(bs,irs))*(exp(-1j*(2*pi*db_i(bs,irs)./lambda)));
hb_i(irs,bs)=db_i(bs,irs);
end
end
%% channel between IRS and IRS
hi_i= cell(100,100);
rr=11;
for irs1 = 1:(L-1) % IRS1
thetaa=2*pi*rand(rr) ;
thetae=2*pi*rand(rr) ;
phi_a=2*pi*rand(rr) ;
phi_e=2*pi*rand(rr) ;
ij=1;
for irs2 = (irs1+1):L % IRS2
%% AoA arrival
sij2=array_resp(10,phi_a(ij),phi_e(ij));
sij1=array_resp(10,thetaa(ij),thetae(ij));
hi_i(irs1,irs2)=(sqrt(alpha)/di_i(irs1,irs2))*(exp(-1j*(2*pi*di_i(irs1,irs2)/lambda)))*sij2*sij1'; %% distance between the IRSs i want a hi_i 100x100 matrix for each iteration but dimensions error occurs
ij=ij+1;
end
rr=rr-1;
end

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by