使用 Foor 循环进行绘图



我写了下面的脚本。但是我正在尝试: 剧情fvsL情节 (fvsL), (Hrvs L), (HtvsL) 一次在差异情节中 (我不想为 wach plot 创建不同的m文件) 对于第一项,我添加了一个 for 循环,但是,它无法绘制,也不显示任何内容或显示绘图。你能告诉我这里是什么吗? 代码为:

clc;
clear;
close all;
%Enter EIRP and Gain
prompt='Is Pt entered in dBw or Watt? Enter dB or W: ';
Pt=input('Enter the Transmiiting Power: ');
inp = input(prompt,'s');
%inp = upper(inp);
if strcmpi(inp,'W')
Pt = 10*log10(Pt);
disp(Pt);
end
Gt=input('Enter Transmitter Antenna Gain: ');
Gr=input('Enter Reciever Antenna Gain: ');
f=input('Enter Operating Frequency in MHz (150 MHz < f < 2000 MHz): ');
while (f<150 || f>2000)
fprintf(2,'nFrequency must be between 150 MHz to 1920 MHzn');
f=input('Enter Operating Frequency in MHz (150 MHz < f < 2000 MHz): ');
end
% Extended Hata Model

if (f>1920)
fprintf(2,'nYou need to use Extended Hata Model (Cost-231)n');
prompt='n Medium city (M)n Suburban Area (S) n Metropolitan Center (C)n';
inp = input(prompt,'s');
inp = upper(inp);
for i=150:50:length(f)
Ht=input('BS antenna Height in m (30m<Ht<200m): ');
while (Ht<30 || Ht>200)
fprintf(2,'nFrequency must be between 3m to 1000mn');
Ht=input('BS antenna Height in m (30m<Ht<1000m): ');
end

Hr=input('MS anenna Height in m(1m<Hr<10m): ');
while (Hr<1 || Hr>10)
fprintf(2,'nReciever Height must be between 1m to 10mn');
Hr=input('Mobile antenna Height in m (1m<Hr<10m): ');
end


d=input('Distance bt Tx and Rx in Km (1Km<d<20Km) : ');
while (d<1 || d>20)
fprintf(2,'nDistance must be between 1Km to 20Kmn');
d=input('Distance bt Tx and Rx in Km (1Km<d<20 Km): ');
end
if strcmp(inp,'M')
for i=150:50:length(f)
cm=0;
ahr=(1.1*log10(f(i))-0.7)*Hr-1.56*log10(f(i))-0.8;
L(i)=46.3+33.9*log10(f(i))-13.82*log10(Ht)-ahr+(44.9-6.55*log10(Hr))*log10(d)+cm;
end
plot(f,L)
elseif strcmp(inp,'S')
for i=150:50:length(f)
cm=1;
ahr=(1.1*log10(f(i))-0.7)*Hr-1.56*log10(f(i))-0.8;
L(i)=46.3+33.9*log10(f(i))-13.82*log10(Ht)-ahr+(44.9-6.55*log10(Hr))*log10(d)+cm;
end
plot(f,L)
else 
for i=150:50:length(f)
cm=3;
ahr=3.2*(log10(11.75*Hr))^2-4.97;
L(i)=46.3+33.9*log10(f(i))-13.82*log10(Ht)-ahr+(44.9-6.55*log10(Hr))*log10(d)+cm;
end
plot(f,L)
end
end
elseif (f>1500 && f<=1920)
fprintf(2,'nYou need to use Okumura Model or Extended Hata Model (Cost-231)n');
prompt = 'Which Model do you intend to use? (Insert O for Okumora or E for Exctended Hata (Cost-231)';
inp = input(prompt,'s');
inp = upper(inp);
if strcmp(inp,'O')
warning('Okumora Model is selceted')

Ht=input('BS antenna Height in m (30m<Ht<1000m): ');
while (Ht<30 || Ht>1000)
fprintf(2,'nFrequency must be between 3m to 1000mn');
Ht=input('BS antenna Height in m (30m<Ht<1000m): ');
end

Hr=input('MS anenna Height in m(3m<Hr<10m): ');
while (Hr<3 || Hr>10)
fprintf(2,'nReciever Height must be between 30m to 100mn');
Hr=input('Mobile antenna Height in m (30m<Ht<1000m): ');
end


d=input('Distance bt Tx and Rx in Km (1Km<d<100 Km) : ');
while (d<1 || d>100)
fprintf(2,'nDistance must be between 30m to 100mn');
d=input('Distance bt Tx and Rx in Km (1Km<d<100 Km): ');
end

Amu=input('Enter the Median Attenuation in dB: ');
Ga=input('Enter Correction Factor due to environment type: ');
Kter=input('Correction factor on Rolling Hilly Terain (Undulation): ');
Ksp=input('Correction Factor on Sloping Terrain');
Kls=input('Correction factor on Land Sea Terrain');
Lf=32.45+20*log(f)+20*log10(d);
GHt=20*log(Ht/200);
if(Hr>3)
GHr=20*log10(Hr/3);
else
GHr=10*log10(Hr/3);
end

else
fprintf(2,'nYou need to use Extended Hata Model (Cost-231)n');
prompt='n Medium city (M)n Suburban Area (S) n Metropolitan Center (C)n';
inp = input(prompt,'s');
inp = upper(inp);
Ht=input('BS antenna Height in m (30m<Ht<200m): ');
while (Ht<30 || Ht>200)
fprintf(2,'nFrequency must be between 3m to 1000mn');
Ht=input('BS antenna Height in m (30m<Ht<1000m): ');
end

Hr=input('MS anenna Height in m(1m<Hr<10m): ');
while (Hr<1 || Hr>10)
fprintf(2,'nReciever Height must be between 30m to 100mn');
Hr=input('Mobile antenna Height in m (30m<Ht<1000m): ');
end


d=input('Distance bt Tx and Rx in Km (1Km<d<20Km) : ');
while (d<1 || d>20)
fprintf(2,'nDistance must be between 1Km to 20Kmn');
d=input('Distance bt Tx and Rx in Km (1Km<d<20 Km): ');
end
if strcmp(inp,'M')
cm=0;
ahr=(1.1*log10(f)-0.7)*Hr-1.56*log10(f)-0.8;
L=46.3+33.9*log10(f)-13.82*log10(Ht)-ahr+(44.9-6.55*log10(Hr))*log10(d)+cm;

elseif strcmp(inp,'S')
cm=1;
ahr=(1.1*log10(f)-0.7)*Hr-1.56*log10(f)-0.8;
L=46.3+33.9*log10(f)-13.82*log10(Ht)-ahr+(44.9-6.55*log10(Hr))*log10(d)+cm;
else 
cm=3;
ahr=3.2*(log10(11.75*Hr))^2-4.97;
L=46.3+33.9*log10(f)-13.82*log10(Ht)-ahr+(44.9-6.55*log10(Hr))*log10(d)+cm;
end

end     
L=Lf+Amu-GHt-GHr-Ga;

disp(L)
plot(Hr,L);
title('Frequency versus Loss in dB for suburben area using Ukumara Model ');
xlabel('Frequency in MHz');
ylabel('Path Loss in dB');
else
prompt = 'Which Model do you intend to use? (Insert O for Okumora or H for Hata or E for Extended Hata(Cost-231))';
inp = input(prompt,'s');
inp = upper(inp);
if strcmp(inp,'O')
warning('Okumora Model is selceted');
Ht=input('BS antenna Height in m (30m<Ht<1000m): ');
while (Ht<30 || Ht>1000)
fprintf(2,'nFrequency must be between 3m to 1000mn');
Ht=input('BS antenna Height in m (30m<Ht<1000m): ');
end

Hr=input('MS anenna Height in m(3m<Hr<10m): ');
while (Hr<3 || Hr>10)
fprintf(2,'nReciever Height must be between 30m to 100mn');
Hr=input('Mobile antenna Height in m (30m<Ht<1000m): ');
end


d=input('Distance bt Tx and Rx in Km (1Km<d<100 Km) : ');
while (d<1 || d>100)
fprintf(2,'nDistance must be between 30m to 100mn');
d=input('Distance bt Tx and Rx in Km (1Km<d<100 Km): ');
end
Amu=input('Enter the Median Attenuation in dB: ');
Ga=input('Enter Correction Factor due to environment type: ');
Kter=input('Correction factor on Rolling Hilly Terain (Undulation): ');
Ksp=input('Correction Factor on Sloping Terrain');
Kls=input('Correction factor on Land Sea Terrain');
Lf=32.45+20*log(f)+20*log10(d);
GHt=20*log10(Ht/200);
if(Hr>3)
GHr=20*log(Hr/3);
else
GHr=10*log10(Hr/3);
end
L=Lf+Amu-GHt-GHr-Ga;

disp(L)
plot(Hr,L);
title('Frequency versus Loss in dB for suburban area using Ukumara Model ');
xlabel('Frequency in MHz');
ylabel('Path Loss in dB');
grid on;
elseif strcmp(inp,'H')
fprintf(2,'n Hata Model is selected n');
Ht=input('Basestaion anenna Height in m(3m<Hr<1000m): ');
while (Ht<30 || Ht>1000)
fprintf(2,'nFrequency must be between 3m to 1000mn');
Ht=input('BS antenna Height in m (30m<Ht<1000m): ');
end

Hr=input('MS anenna Height in m(3m<Hr<10m): ');
while (Hr<3 || Hr>10)
fprintf(2,'nReciever Height must be between 30m to 100mn');
Hr=input('Mobile antenna Height in m (30m<Ht<1000m): ');
end


d=input('Distance bt Tx and Rx in Km (1Km<d<200 Km) : ');
while (d<1 || d>200)
fprintf(2,'nDistance must be between 30m to 200mn');
d=input('Distance bt Tx and Rx in Km (1Km<d<100 Km): ');
end
prompt=' Which area is targeted? n Small or Medium Sized City? (M) n Large City (L)n Suburban area (S) n Open rural area(O) n';
inp=input(prompt,'s');
inp = upper(inp);
if strcmp(inp,'S')
ahr=(1.1*log10(f)-0.7)*Hr-1.56*log10(f)-0.8;
L=68.55+26.16*log10(f)-13.82*log10(Ht)-ahr+(44.9-6.55*log10(Ht))*log10(d);
elseif strcmp(inp,'L') 
if (f>=300)
ahr=8.9*(log10(1.54*Hr))^2-1.1;
L=68.55+26.16*log10(f)-13.82*log10(Ht)-ahr+(44.9-6.55*log10(Ht))*log10(d);
else
ahr=3.2*(log10(11.75*Hr))^2-4.97;
end

L=68.55+26.16*log10(f)-13.82*log10(Ht)-ahr+(44.9-6.55*log10(Ht))*log10(d);                    
elseif strcmp(inp,'S')
ahr=(1.1*log10(f)-0.7)*Hr-1.56*log10(f)-0.8;
L=68.55+26.16*log10(f)-13.82*log10(Ht)-ahr+(44.9-6.55*log(Ht))*log10(d)-2*(log10(f/28))^2-5.4;
elseif strcmp(inp,'O')   
ahr=(1.1*log10(f)-0.7)*Hr-1.56*log10(f)-0.8;
L=68.55+26.16*log10(f)-13.82*log10(Ht)-ahr+(44.9-6.55*log10(Ht))*log10(d)-4.78*(log10(f))^2-18.33*log10(f)-40.98;                
end    
else
prompt='n Medium city (M)n Suburban Area (S) n Metropolitan Center (C)n';
inp = input(prompt,'s');
inp = upper(inp);

Ht=input('BS antenna Height in m (30m<Ht<200m): ');
while (Ht<30 || Ht>200)
fprintf(2,'nFrequency must be between 3m to 1000mn');
Ht=input('BS antenna Height in m (30m<Ht<1000m): ');
end

Hr=input('MS anenna Height in m(1m<Hr<10m): ');
while (Hr<1 || Hr>10)
fprintf(2,'nReciever Height must be between 30m to 100mn');
Hr=input('Mobile antenna Height in m (30m<Ht<1000m): ');
end


d=input('Distance bt Tx and Rx in Km (1Km<d<20Km) : ');
while (d<1 || d>20)
fprintf(2,'nDistance must be between 1Km to 20Kmn');
d=input('Distance bt Tx and Rx in Km (1Km<d<20 Km): ');
end
if strcmp(inp,'M')
cm=0;
ahr=(1.1*log10(f)-0.7)*Hr-1.56*log10(f)-0.8;
L=46.3+33.9*log10(f)-13.82*log10(Ht)-ahr+(44.9-6.55*log10(Hr))*log10(d)+cm;

elseif strcmp(inp,'S')
cm=1;
ahr=(1.1*log10(f)-0.7)*Hr-1.56*log10(f)-0.8;
L=46.3+33.9*log10(f)-13.82*log10(Ht)-ahr+(44.9-6.55*log10(Hr))*log10(d)+cm;
else 
cm=3;
ahr=3.2*(log10(11.75*Hr))^2-4.97;
L=46.3+33.9*log10(f)-13.82*log10(Ht)-ahr+(44.9-6.55*log10(Hr))*log10(d)+cm;
end



end
end

对于以下输入,运行以M结束,没有任何反应:

输入转换功率:23 Pt是以dBw还是瓦特输入的?进入 分贝或宽:W 13.6173

输入发射机天线增益:23 输入接收天线增益:3 输入工作频率(兆赫 (150 MHz

您需要使用扩展畑模型(成本-231)

中等城市 (M) 郊区 (S) 大都会中心 (C) M

调试是查找问题的好方法。这是第 32 行中的错误:

for i=150:50:length(f)

你知道,f是一个数字,所以f的长度是1。因此,for 循环将不会运行。

相关内容

  • 没有找到相关文章

最新更新