Can anyone help me to rectify this matlab code? i
Afficher commentaires plus anciens
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 commentaires
DGM
le 19 Juil 2021
What exactly is the problem? The code runs without error. If it's not doing something you expect, you'll have to explain.
Mudasir Bakshi
le 19 Juil 2021
Mudasir Bakshi
le 19 Juil 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;
The above plot is shown up on running the give code. What errors you are getting? Specify the errors and line number.
Mudasir Bakshi
le 19 Juil 2021
Torsten
le 19 Juil 2021
Please include the exact error message.
DGM
le 19 Juil 2021
What errors are you getting? I don't get any errors when I run it.
Mudasir Bakshi
le 19 Juil 2021
Torsten
le 19 Juil 2021
theta_2 seems to be an array, and you can't assign an array to the single scalar element y(1).
Check size(theta_2).
Mudasir Bakshi
le 19 Juil 2021
Torsten
le 19 Juil 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.
Réponses (1)
KSSV
le 19 Juil 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;
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
