Can anyone help me to rectify this matlab code? i
이전 댓글 표시
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
DGM
2021년 7월 19일
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
2021년 7월 19일
Mudasir Bakshi
2021년 7월 19일
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
2021년 7월 19일
Torsten
2021년 7월 19일
Please include the exact error message.
DGM
2021년 7월 19일
What errors are you getting? I don't get any errors when I run it.
Mudasir Bakshi
2021년 7월 19일
Torsten
2021년 7월 19일
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
2021년 7월 19일
Torsten
2021년 7월 19일
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.
답변 (1개)
KSSV
2021년 7월 19일
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;
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
