I'm running a while loop and I am running in to some problems.
I have the following piece of code:
  Angle_int = 0.5;                    % Initial interpolation angle of attack
  Clmax2d(1,1:length(Yle_wing)) = 3;  % Dummy value
  diff = 0;                         % Dummy value
  while sum(diff < 0) > fix(tol*length(Yle_wing))
      Angle_int = Angle_int + 0.5; % Interpolation angle increases with 0.5 with every iteration
          for j = 1:length(Yle_wing)
          CL3d = interp1(Angle,[cl_matrix(1,j)  cl_matrix(2,j) cl_matrix(3,j)],Angle_int,'linear');
          CL_3DD(:,j) = CL3d;
          end  
      diff = (Clmax2d - CL_3DD);     % Difference between Cl2d and Cl3d
      Angle_stall = Angle_int;
      CL_3D = CL_3DD;
  end
For some reason,  CL_3D = CL_3DD; and Angle_stall = Angle_int; seem to disappear when the while loop finishes. Hence, I cannot use their converged values ahead of the while loop since these variables are not recognized. I get the following error:
Undefined function or variable "CL_3D".
Hence, does someone knows what I am doing wrong? or any tips would be welcome as well.
Thanks in advance, cheers
 
     
     
    