Can anyone help me to rectify this matlab code? i

4 Ansichten (letzte 30 Tage)
Mudasir Bakshi
Mudasir Bakshi am 19 Jul. 2021
Beantwortet: KSSV am 19 Jul. 2021
clc; clear variables; close all;
N = 10.^6;
d1 = 0.3; %Source to user 1 distance
d2 = 1; %Source to user 2 distance
d12 = 1-d1; %User 1 to user 2 distance
alpha=2;
Omega_1=d1.^(-alpha);
Omega_2=d2.^(-alpha);
Omega_12=d12.^(-alpha);
m = 1;
%h1=sqrt(gamrnd (m,Omega_1./m,1,N));
%h2=sqrt(gamrnd (m,Omega_2./m,1,N));
%h12=sqrt(gamrnd (m,Omega_12./m,1,N));
%g1 = (abs(h1)).^2;
%g2 = (abs(h2)).^2;
%g12 = (abs(h12)).^2;
%gLI=10.^(-1.5);
SNR = -10:5:50; %SNR in dB
snr = db2pow(SNR); %SNR linear
a1 = 0.2; a2 = 0.8; %Power allocation coefficients
R2 = 0.5; %Target rate
R1=3;
gamma_th1_FD=2.^R1-1;
gamma_th2_FD=2.^R2-1;
tau_1=gamma_th2_FD./(snr.*(a2-a1.*gamma_th2_FD));
beta_1=gamma_th1_FD./(a1.*snr);
theta_1=max(tau_1,beta_1);
gamma_th1_HD=2.^(2.*R1)-1;
gamma_th2_HD=2.^(2.*R2)-1;
tau_2=gamma_th2_HD./(snr.*(a2-a1.*gamma_th2_HD));
beta_2=gamma_th1_HD./(a1.*snr);
theta_2=max(tau_2,beta_2);
y= zeros(m,1);
for i=0:m-1
k=i+1;
y=(1./factorial(k)).*(theta_2.^k).*(m./Omega_1).^k;
end
y1=sum(y);
y2=exp(-(m.*theta_2./Omega_1)).*y1;
p=1-y2;
plot(SNR,p,'--dc','linewidth',2);hold on;grid on;
  11 Kommentare
Mudasir Bakshi
Mudasir Bakshi am 19 Jul. 2021
yes that is the problem ,how can i remove this error?
Torsten
Torsten am 19 Jul. 2021
Maybe you can use y(:,k) instead of y(k).
But since I don't know what you are trying to do, you are the only person who knows how to change the code adequately.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

KSSV
KSSV am 19 Jul. 2021
clc; clear variables; close all;
N = 10.^6;
d1 = 0.3; %Source to user 1 distance
d2 = 1; %Source to user 2 distance
d12 = 1-d1; %User 1 to user 2 distance
alpha=2;
Omega_1=d1.^(-alpha);
Omega_2=d2.^(-alpha);
Omega_12=d12.^(-alpha);
m = 1;
%h1=sqrt(gamrnd (m,Omega_1./m,1,N));
%h2=sqrt(gamrnd (m,Omega_2./m,1,N));
%h12=sqrt(gamrnd (m,Omega_12./m,1,N));
%g1 = (abs(h1)).^2;
%g2 = (abs(h2)).^2;
%g12 = (abs(h12)).^2;
%gLI=10.^(-1.5);
SNR = -10:5:50; %SNR in dB
snr = db2pow(SNR); %SNR linear
a1 = 0.2; a2 = 0.8; %Power allocation coefficients
R2 = 0.5; %Target rate
R1=3;
gamma_th1_FD=2.^R1-1;
gamma_th2_FD=2.^R2-1;
tau_1=gamma_th2_FD./(snr.*(a2-a1.*gamma_th2_FD));
beta_1=gamma_th1_FD./(a1.*snr);
theta_1=max(tau_1,beta_1);
gamma_th1_HD=2.^(2.*R1)-1;
gamma_th2_HD=2.^(2.*R2)-1;
tau_2=gamma_th2_HD./(snr.*(a2-a1.*gamma_th2_HD));
beta_2=gamma_th1_HD./(a1.*snr);
theta_2=max(tau_2,beta_2);
%m=ones(1,length(snr));
y= cell(m,1);
for i=0:m-1
k=i+1;
y{k}=(1./factorial(k)).*(theta_2.^k).*(m./Omega_1).^k;
end
y = cell2mat(y) ;
y1=sum(y);
y2=exp(-(m.*theta_2./Omega_1)).*y1;
p=1-y2;
plot(SNR,p,'--dc','linewidth',2);hold on;grid on;

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by