I am facing problem regarding storage of values for d() using for loop which is of 100x100 size for each iteration of a and k.

1 view (last 30 days)
clc
clear all
close all
%% Cell generation
alpha=4; % pth loss exponent
p=-30; % power= 10db
p_lin=db2pow(p);
radius=15;
lambda=0.6;
l=lambda/2;
alpha=(lambda/(4*pi))^2;
elements=10;
L=12;
N=4;
K=4;
%% Large intelligent reflecting surfaces
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];
plot(X3,Y3,'r*','MarkerSize', 10, 'Linewidth', 2);
%legend('','Base stations','Users','Intelligent Reflecting Surfaces')
hold on
elements=10;
p=0;
%% loop for the elements of irs% D=zeros(1,1200);
for t=1:L
for v=1:elements
for w=1:elements
x3(v,w) = X3(t,1)+p; % X coordinate of an element of IRS for plotting
x_e = zeros(10,10, 12);
y_e = zeros(10,10,12);
y3(v,w) = Y3(t,1); % Y coordinate of an element of IRS for plotting
p=w*l;
x_e(v,w,t) =x3(v,w);
y_e(v,w,t)= y3(v,w);
end
p=0;
Y3(t,1) = Y3(t,1) + l;
end
plot(x3,y3,'bo')
% B=x_e(:,:,1)';
% C=reshape(B,1,[]);
end
%% loop to evaluate distance between IRS and IRS
for a=1:L-1
dd=a;
for k=a+1:L-1
bb=k+1;
for l=1:elements
for m=1:elements
for n=1:elements
for o=1:elements
d(a,bb)=sqrt((x_e(n,o,k)-x_e(l,m,a))^2+(y_e(n,o,k)-y_e(l,m,a))^2)
end
end
end
end
end
end
  2 Comments
Walter Roberson
Walter Roberson on 19 Dec 2021
You should be using a 4 dimensional d array such as
d(a,bb,n,o)=sqrt((x_e(n,o,k)-x_e(l,m,a))^2+(y_e(n,o,k)-y_e(l,m,a))^2);
Except that I would suggest creating a local 2D array in the inner loop, like
for a=1:L-1
dd=a;
for k=a+1:L-1
bb=k+1;
for l=1:elements
for m=1:elements
t = zeros(elements, elements);
for n=1:elements
for o=1:elements
t(n,o)=sqrt((x_e(n,o,k)-x_e(l,m,a))^2+(y_e(n,o,k)-y_e(l,m,a))^2);
end
end
dd(a,bb,:,:) = t;
end
end
end
end
That would be more efficient.

Sign in to comment.

Answers (1)

Jan
Jan on 19 Dec 2021
You overwrite the data by zeros repeatedly:
for t=1:L
for v=1:elements
for w=1:elements
% Here all formerly written values of x_e and y_e
% are overwritten with zeros. Only the last iteration
% is kept:
x_e = zeros(10,10, 12);
y_e = zeros(10,10,12);
x_e(v,w,t) =x3(v,w);
y_e(v,w,t)= y3(v,w);
end
end
end
I guess you want to move the zeros() command before the loops.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!