Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab:在使用'';如果'';陈述_Matlab_If Statement_Plot_Legend - Fatal编程技术网

Matlab:在使用'';如果'';陈述

Matlab:在使用'';如果'';陈述,matlab,if-statement,plot,legend,Matlab,If Statement,Plot,Legend,我正在尝试绘制一些函数并显示图例。我的代码可以在下面找到: %% DATCOM spanloading method tol = Input.tol; iteration = 0; difference =0; AVL_step = 0.25; Interp_step =0.1; AVLruns = 3; Angle = ((1:AVLruns)*AVL_step)+AOA; while sum(difference < 0) <= fix(tol*Input.Surface

我正在尝试绘制一些函数并显示图例。我的代码可以在下面找到:

%% DATCOM spanloading method
tol = Input.tol; 
iteration = 0;
difference =0;
AVL_step = 0.25;
Interp_step =0.1;
AVLruns = 3;
Angle = ((1:AVLruns)*AVL_step)+AOA;


 while sum(difference < 0) <= fix(tol*Input.Surface.Nspan) && iteration < 100

iteration = iteration +1;


                          if iteration <= AVLruns
                                    AOA =  AOA + AVL_step;
                                    [Yle_wing,Spanloading] = obj.AVLspanloading(Input,CLa,AOA);                % Creates spanloading with AVL
                                    Scalefunc = 1/(max(Yle_wing)-min(Yle_wing));                               % Scale function
                                    Ynorm= ((Yle_wing - min(Yle_wing)) .* Scalefunc)';                         % Normalize semi-span from 0 to 1

                                        if length(YClmax) ~= length(Ynorm) && iteration ==1                                               
                                            Clmax_dist= interp1(YClmax,Clmax_dist,Ynorm,'linear');                   
                                        end 

                            difference = (Clmax_dist - Spanloading);                                           % Difference between resampled  CL3d and Cl2d  
                            cl_matrix(iteration,:) = Spanloading;
                          else  
                            AOA =  AOA + Interp_step;
                                    for QQ = 1:Input.Surface.Nspan 
                                        CL3d = interp1(Angle,cl_matrix(:,QQ)',AOA,'linear','extrap');
                                        Spanloading(:,QQ) = CL3d;
                                    end
                            difference = (Clmax_dist - Spanloading); 
                          end



  figure(1)
  pl = plot(Yle_wing,Clmax_dist,'r');
  legendStrs = {'2D Clmax'};
  set(pl,'linewidth',1.5);
  hold on 
  if iteration <= AVLruns
    plot(Yle_wing,Spanloading,'g--o')
    legendStrs = [legendStrs, {'Spanloading by AVL'}];
  else
    plot(Yle_wing,Spanloading)
    legendStrs = [legendStrs, {'Spanloading by extrapolation'}];
  end
  xlabel('2y/b')
  ylabel('Local Cl') 
  title('DATCOM SPANLOADING METHOD')
  legend('boxon')
  legend(legendStrs,'Location','SouthWest');



 end
 if iteration >= 100
     disp('Spanloading did not converge, while loop terminated by reaching maximum iteration count')    
 end
%%DATCOM加载方法
tol=Input.tol;
迭代=0;
差异=0;
AVL_阶跃=0.25;
内台阶=0.1;
AVLruns=3;
角度=((1:AVLruns)*AVL_步长)+AOA;

当求和(差值<0)时,您可以将单元格数组作为输入传递给
图例。维护字符串的单元格数组,并在plot语句之后立即向其添加相关字符串

pl = plot(Yle_wing,Clmax_dist,'r');
legendStrs = {'2D Clmax'};
然后在后面的
if-else
块中

if iteration <= AVLruns
    plot(Yle_wing,Spanloading,'g--o')
    legendStrs = [legendStrs, {'Spanloading by AVL'}];
    set(pl,'linewidth',1.5);
else
    plot(Yle_wing,Spanloading)
    legendStrs = [legendStrs, {'Spanloading by extrapolation'}];
end

我们需要看到更多。这显然是在循环中完成的,所以给我们更多的上下文。这个代码本身不会运行。是的,我不理解。实际上,这段代码与其他8个函数文件一起工作。因此,我必须上传所有文件才能运行这段代码。但是,我将尝试获取作为绘图命令输入的向量。只需再次查看绘图的
DisplayName
属性和相关属性。另外,也许您可以在代码中突出显示循环的位置?嘿,“Random Guy”?只要if语句条件发生变化,第三个plot命令激活,您的方法就会更改我的图例描述。然而,在图例中,我仍然只看到红线和绿线。此外,如果满足第一个if语句条件。绿线表示“通过AVL加载”,当第二个if语句条件保持不变时,绿线表示“通过外推加载”。这并不完全是我想要的,因为我希望绘图显示所有三种颜色,红、绿和蓝。需要查看更多代码来了解发生了什么<代码>p1=绘图(…
也在循环内,对吗?
legend(legendStrs,'Location','SouthWest');