No connecting lines in plots

7 views (last 30 days)
Abdul Hanan
Abdul Hanan on 22 Jan 2021
Commented: Mario Malic on 22 Jan 2021
Plot is just giving points instead of making lines between them, can someone help me out?
clc
%noise variance: sigma_1, sigma_2, sigma_3, sigma_4
N_v=-70*0.001;
N_var=1.0*exp(-10);
zeta=0.8;
BW=1*10^6;
%Distances
d_0=-30;
%from BS to UAV
d_1=8;%from BS to U1
d_2=30;%from UAV to U2
d_3=35;%from UAV to U3
%minimum rate requirements R_1^1 and R_2^1
R=1;
%Total power at the BS
%SI cancellation level
rho=-30;
%delay at relay
tau=0.5;
%circuit power consumption
P_c=31.6228;
%channel from BS to U1
chan1 = rayleighchan;
c11=chan1.PathGains;
h_1=1/sqrt(2)*abs( c11 )^2;
H_1=conj(h_1)*h_1;
%Loop channel
chan3 = rayleighchan;
c33=chan3.PathGains;
h_LI=1/sqrt(2)*abs( c33 )^2;
H_LI=conj(h_LI).*h_LI;
%channel from BS to UAV
beta=-65;
chan2 = rayleighchan;
c22=chan2.PathGains;
h_NLoS=1/sqrt(2)*abs( c22 )^2;
H_NLoS=conj(h_NLoS)*h_NLoS;
%signals:
chan=ricianchan;
chan=chan.PathGains;
h_LoS=1/sqrt(2)*abs(chan)^2;
omega_0=asin(30/-30);
omega_2=asin(30/30);
omega_3=asin(30/35);
K_0=5*exp(0.7*omega_0);
K_2=5*exp(0.7*omega_2);
K_3=5*exp(0.7*omega_3);
p_LOS_0=1/(1+42*exp(-9*omega_0));
p_LOS_2=1/(1+42*exp(-9*omega_2));
p_LOS_3=1/(1+42*exp(-9*omega_3));
tau_0=-1*p_LOS_0-1;
tau_2=-1*p_LOS_2-1;
tau_3=-1*p_LOS_3-1;
h_0_bar=(sqrt(K_0/(K_0+1))*h_LoS)+sqrt(1/K_0+1)*h_NLoS;
h_2_bar=(sqrt(K_2/(K_2+1))*h_LoS)+sqrt(1/K_2+1)*h_NLoS;
h_3_bar=(sqrt(K_3/(K_3+1))*h_LoS)+sqrt(1/K_3+1)*h_NLoS;
h_0=(beta*h_0_bar)/(d_0^(tau_0));
h_2=(beta*h_2_bar)/(d_2^(tau_2));
h_3=(beta*h_3_bar)/(d_3^(tau_3));
H_0=conj(h_0).*h_0;
H_2=conj(h_2).*h_2;
H_3=conj(h_3).*h_3;
%%%%%%%%%%%%%
%Time-slot 1%
%%%%%%%%%%%%%
PZ=[5,10,15,20,25,30];
for P_B=5:5:30
alpha=0.4;
%Power allocation co-efficients
w_1=0.4*P_B;
w_2=0.6*P_B;
w_0=w_2*alpha;
%SNR values
y_02=(alpha*conj(w_2)*H_0*w_2)/(alpha*(conj(w_1)*H_0*w_1+rho*(conj(w_0)*H_LI*w_0+N_var)+N_var));
y_12=(conj(w_2)*H_1*w_2)/((conj(w_1)*H_1*w_1)+N_var);
y_11=(conj(w_1)*H_1*w_1)/(N_var);
y_22=(conj(w_0)*H_2*w_0)/N_var;
%Rate of User 1;
Rate1=BW*log2(1+y_11);
%Rate of User 2;
r1=BW*log2(1+y_12);
r2=BW*log2(1+y_22);
r3=BW*log2(1+y_02);
if r1<r2
Rate2=r1;
elseif r2<r3
Rate2=r2;
else
Rate2=r3;
end
%Total sum
R_sum=Rate1+Rate2;
%Power at the relay
P_0=(zeta*(1-alpha)*(conj(w_1)*H_0*w_1+conj(w_2)*H_0*w_2+conj(w_0)*H_LI*w_0))/(1-tau);
%Constraints%
ConsP_B=w_1+w_2;
%Total power of the system
P_sum=conj(w_1)*w_1+conj(w_2)*w_2+conj(w_0)*w_0+P_c-P_0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Generation of feasible point%
f_1=(2*real(conj(w_1)*H_1*w_1)/(N_var))-((conj(w_1)*H_1*w_1)/(N_var));
Gamma=(2^R)-1;
f1=f_1/Gamma;
f_2=(2*real(conj(w_2)*H_1*w_2)/(conj(w_1)*H_1*w_1+N_var)-((conj(w_2)*H_1*w_2)/(conj(w_1)*H_1*w_1+N_var)^2))*(conj(w_1)*H_1*w_1+N_var);
f_3=(2*real(conj(w_0)*H_2*w_0)/(N_var))-((conj(w_0)*H_2*w_0)/(N_var));
f_4=(2*real(conj(w_2)*H_0*w_2)/(conj(w_1)*H_0*w_1+rho*conj(w_0)*H_LI*w_0+N_var+N_var/alpha)-((conj(w_2)*H_0*w_2)/((conj(w_1)*H_0*w_1+rho*conj(w_0)*H_LI*w_0+N_var+N_var/alpha)^2)))*(conj(w_1)*H_0*w_1+rho*conj(w_0)*H_LI*w_0+N_var+N_var/alpha);
if f_2<f_3
o=f_2;
elseif f_2<f_4
o=f_2;
else
o=f_3;
end
f=(zeta*(1-alpha)*(2*real(conj(w_1)*H_0*w_1-conj(w_1)*H_0*w_1)+(2*real(conj(w_2)*H_0*w_2)-conj(w_2)*H_0*w_2)+(2*real(conj(w_0)*H_LI*w_0)-w_0*H_LI*w_0)))/(1-tau);
%Value of w that maximizes the function f1 is w_1=0.4 and w_2=0.6 which satisfies all the constraints
%%%%%%%%%%%%
%Time-slot2%
%%%%%%%%%%%%
%Power allocation co-efficients
w_4=0.4*P_B;
w_3=0.6*P_B;
w_5=w_3*alpha;
%SNR values
y_53=(alpha*conj(w_3)*H_0*w_3)/(alpha*(conj(w_4)*H_0*w_4+rho*(conj(w_5)*H_LI*w_5+N_var)+N_var));
y_43=(conj(w_3)*H_1*w_3)/((conj(w_4)*H_1*w_4)+N_var);
y_44=(conj(w_4)*H_1*w_4)/(N_var);
y_33=(conj(w_5)*H_3*w_5)/N_var;
%Rate of User 1;
Rate11=log(1+y_44);
%Rate of User 2;
r11=log(1+y_43);
r22=log(1+y_33);
r33=log(1+y_53);
if r11<r22
Rate22=r11;
elseif r22<r33
Rate22=r22;
else
Rate22=r33;
end
%Total sum
R_summ=Rate11+Rate22;
%Power at the relay
P_5=(zeta*(1-alpha)*(conj(w_4)*H_0*w_4+conj(w_3)*H_0*w_3+conj(w_5)*H_LI*w_5))/(1-tau);
%Tota Power constraint
Cons=w_4'*w_4+w_3'*w_3;
%Total power of the system
P_summ=w_4+w_3+w_5+P_c-P_0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Generation of feasible point%
p_1=(2*real(conj(w_4)*H_1*w_4)/(N_var))-((conj(w_4)*H_1*w_4)/(N_var));
p1=p_1/Gamma;
p_2=(2*real(conj(w_3)*H_1*w_3)/(conj(w_4)*H_1*w_4+N_var)-((conj(w_3)*H_1*w_3)/(conj(w_4)*H_1*w_4+N_var)^2))*(conj(w_4)*H_1*w_4+N_var);
p_3=(2*real(conj(w_5)*H_3*w_5)/(N_var))-((conj(w_5)*H_3*w_5)/(N_var));
p_4=(2*real(conj(w_3)*H_0*w_3)/(conj(w_4)*H_0*w_4+rho*conj(w_5)*H_LI*w_5+N_var+N_var/alpha)-((conj(w_2)*H_0*w_2)/((conj(w_1)*H_0*w_1+rho*conj(w_0)*H_LI*w_0+N_var+N_var/alpha)^2)))*(conj(w_1)*H_0*w_1+rho*conj(w_0)*H_LI*w_0+N_var+N_var/alpha);
if p_2<p_3
o2=f_2;
elseif p_2<p_4
o2=p_2;
else
o2=p_3;
end
p=(zeta*(1-alpha)*(2*real(conj(w_1)*H_0*w_1-conj(w_1)*H_0*w_1)+(2*real(conj(w_2)*H_0*w_2)-conj(w_2)*H_0*w_2)+(2*real(conj(w_0)*H_LI*w_0)-w_0*H_LI*w_0)))/(1-tau);
%%%%%%%%%%%%%%%%%%%%%%%%%
%Total system Efficiency%
P_T=P_sum+P_summ;
R_T=Rate1+Rate2+Rate11+Rate22;
nEE=R_T/P_T
P_B
plot(P_B,nEE,'r*-'); hold on
xlabel('Power Budget at BS');
ylabel('Average Energy Efficiency');
title('Plot of nEE vs P_B')
end
  1 Comment
Mario Malic
Mario Malic on 22 Jan 2021
That happens when you plot a single point on the graph. If your P_B and nEE were vectors of the same length, you'd see points connected by line.
I hope that you'll figure out how to fix your problem yourself, because reading the whole code is hard, especially with so many unnecessary different names for variables.
Idea is to move your plot function out of for loop, and calculate nEE this way
ii = 1;
for P_B=5:5:30
% code
nEE(ii) =
ii = ii + 1;
% code
end
plot(P_B,nEE,'r*-');

Sign in to comment.

Answers (0)

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!