Didnot get the value after executing

2 次查看(过去 30 天)
Hi Sir,after running this code ,MATLAB didnot display the Rhn answer and typing Rhn in the command window i get undefined variable.Sir kindly specify the error please
close all
clear all
TN=4;
n_vec=1:TN;
simulations=10000;
for n=n_vec
E=[];
for sim=1:simulations
B=0.3; %idle period
phi=(1-B)/n; %backscattering time
Bbn=20*1000; %transmission rate by backscatter communication
Rbn =(phi*Bbn); %no of bits transmitted by backscattering in busy period
PT=17*1000; %PT transmit power 17kW
del=0.6; %delta energy harvesting efficiency
No=0.01; %noise power
d= 8304.215; % distance from PT to ST ,5.16 miles, 8.304215km
sigma=2.7; %pathloss(db) in urban area cellular radio btw 2.7 ro 3.5
for r=TN;
g=rand(1,r);
PRn=((del*PT*g)./(1-d^sigma)*No); %generating negative value due to No
Kn=0.6; %transmission efficiency
Bandwidth=100*1000;
Psi=Kn*Bandwidth;
tau=B/n;
Ehn=((1-B-phi)*PRn);
E=[E Ehn];
sorted=sort(Ehn,'descend');
total=length(sorted);
half=(total/2);
max=sorted(1:half);
min=sorted(half+1:end);
end
for Max=1:max
rr=TN/2;
h=rand(1,rr);
Rhn=(tau*Psi*log(2))*(1+((max*h)/(tau*No)));
end
end
end
  2 个评论
Maheen Fazal
Maheen Fazal 2019-2-14
It is giving the value zero for max with the last for loop but when i remove it the max value get changed,i didnot understand how and why

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2019-2-14
max and min are vectors. When you use a vector as a bound on a for loop, then only the first element in the vector is used.
Your for Max loop is overwriting Rhn in every iteration, so you might as well only use the last iteration.
Naming variables max or min is quite likely to lead to problems later when you try to use max() or min() as functions. At the very least it confuses readers of the code.

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by