首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用foor循环绘制图

使用foor循环绘制图
EN

Stack Overflow用户
提问于 2020-12-23 23:12:19
回答 1查看 60关注 0票数 0

我写了下面的剧本。不过,我正在尝试:为第一项添加一个for循环,即为第一项创建不同的fL绘图(f vs L)、(Hr vs L)、(Ht vs L)的第一项(我不想为wach绘图创建不同的m文件),但是它不能绘图,也不会显示任何情节。你能告诉我什么是不对的吗?守则是:

代码语言:javascript
复制
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 MHz\n');
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 1000m\n');
      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 10m\n');
      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 20Km\n');
      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 1000m\n');
                   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 100m\n');
              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 100m\n');
              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 1000m\n');
            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 100m\n');
            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 20Km\n');
            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 1000m\n');
                    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 100m\n');
                     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 100m\n');
                    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 1000m\n');
                    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 100m\n');
                     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 200m\n');
                    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 1000m\n');
               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 100m\n');
               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 20Km\n');
              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还是瓦特?输入dB或W: W 13.6173

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

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

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

EN

回答 1

Stack Overflow用户

发布于 2020-12-24 01:57:20

调试是发现问题的好方法。下面是第32行中的错误:

代码语言:javascript
复制
for i=150:50:length(f)

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65432040

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档