File Exchange

image thumbnail

Xfoil Interface Updated

version (13.6 KB) by Louis Edelman
This is an updated version of Gus Brown's code run faster in modern MATLAB and work with Xfoil 6.99


Updated 21 Mar 2018

View License

Copyright (c) 2011, Gus Brown with Modification by Louis Edelman 2015
All rights reserved.
Generates a command script to rapidly run Xfoil for a designated airfoil coordinates file, NACA airfoil, or coordinates matrix. Give the flexibility to pull detailed data (Cp, Cf, H, etc) or just the polar data for a single alpha or vector of alphas. All data is stored as a structured data set with the first left hand operator corresponding to the polar data and the second the detailed results.
Note that you need to have Xfoil 6.99 ( in the same directory to run this code.
If not requested as an output, parsing the detailed results will be skipped to save on cost.
Outputs can be manipulated as standard double precision vectors or matrices using standard structured data calls.

Cite As

Louis Edelman (2020). Xfoil Interface Updated (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (42)

Hallo Louis

Thank you very much for your great work!

I just tried it out. To get the hang of it I tried to compare it to this site which has Xfoil in the background as well. Now, some funny thing happened: If I run you script for alpha = [-1:1:10] everything is fine but if I like to have alpha = [-1:0.25:10] with smaller steps it fails. :(

Warning: One or more alpha values failed to converge. Last converged was alpha = 10.000000. Rerun with
'oper iter ##' command.

I already turned oper iter up. The steps of 0.25 are because the site uses the same small steps. Any idea why it fails?



karthik bv


Thank you for the interface, saved a lot of time here.
I have only one question about the output: the polar file is showing only the last calculated point in the polar i.e: in a polar going from AoA 0:15 the only result line in the polar is for 15 degrees. I tried to check if this is not an issue of a problematic for loop in the code writing over stuff, but it seems to be an xfoil output issue. Any light on what could be going on? Currently on Win 10, XFOIL 6.99. It seems to be a current bug, both Enrico's and Abdulaziz's posts below seem to describe the same issue.
I can see two quick and easy ways to go around it: calling individual angles of attack in a loop, or integrating from the individual panel values, however they are not really smart as you have a lot of repeat calculations (Anijs in the former and integrals in the latter case) that compound when doing many analyses.


great work!

Hello, I am trying to input a coordinate set as a matrix from Matlab. Coordinates are starting from trailing edge counterclockwise. For some reason, the function does not return polar results if I input coordinates, whereas it does for standard NACA profiles. Where can the problem be? I tried to plot the coordinates and they look fine to me

When using XFoil 6.97 for mac, on line 228 change foil.cp(:,jj) = C{3}(:,1); to foil.cp(:,jj) = C{2}(:,1);
This will solve the problem of getting NAN for the cp values.


Apologies, that old line should've been 186. Principle still applies ;).


Hi Louis,
The code really works great. I am using it to perform a parametric study by varying Ncrit values. I have a variation in Ncrit values from 7:0.2:12. So the code runs multiple cases perfectly and some do not converge, that's not an issue. But, every time I decrease the Increment value for the Ncrit below 0.25 the below-mentioned error,
Subscripted assignment dimension mismatch.
Error in xfoil (line 202)
foil.s(:,jj) = D{1}(:,1);

Error in matlabXFOIL (line 49)
[pol,foil] = xfoil('fx63137sm.dat',AOA,Re(j),0,ncrit);
Any suggestions would be appreciated.

Hi Louis,

Thanks for the great work. I have a question, please. In the comment above it says "Give the flexibility to pull detailed data (Cp, Cf, H, etc) or just the polar data for a single alpha or vector of alphas". Would you please educate me how to get Cp from the data. I am actually interested in the minimum and maximum Cp.
Thank you in advance



Can I do this by just editing this part of the script?

if length(pol.alpha) ~= Nalpha % Check if xfoil failed to converge
pol.alpha = NaN;

Louis Edelman

Damian, I've updated a version called xfoilCl that I created back when I made the alpha dominant function for my senior design. It is pretty much the same script with some changes to how it creates the input file for xfoil. I didn't use it as much as the alpha based version and I haven't looked at it at all for 3 years but hopefully it is helpful for you.

As always, I will remind users that the function is essentially a wrapper that calls a .exe (e.g. designed for Windows) with a scripted input file and then parses the output files. It does not do the analysis in MATLAB and is dependen on Drela's Xfoil program. If someone has a modified version for Unix or Mac, I encourage them to upload it but I cannot guarantee any functionality beyond the r2014b Windows environment on which I used the script last personally.

I encourage all users who experience errors to really look at the section of the script that is causing the error. Understanding the code yourself is the fastest way to solving any potential problem in your specific application.


Very nice, works great!
i have some trouble trying to analyse different transition locations on an airfoil while maintaining the same lift coefficient. However, adding the proper command for this ('oper cl 0.3') does not give the desired results, as the required alpha input seems to be dominant.
Does anyone have a suggestion how to solve this? Any help is much appreciated!

my commands for running xfoil:
varargin = ['oper/cl ' num2str(cl) ',oper/iter 2000,oper/vpar xtr ' num2str(trans_forced(i)) ' 1'];
[pol,foil] = xfoil(NACA,alpha,Re,Mach,varargin);

Louis Edelman

Rajarshi Madnal: Xfoil tracks boundary layer properties into the wake so it can properly estimate drag. That is why there are points x>1 in the boundary layer profile outputs.

Johann Widera: What Abhishek said.

Kirk Lewis: I cannot provide any feedback on running this on a Mac. I used the most updated xfoil.exe available when I created the code. If there is no compiled version of 6.99 available for Mac, compile the linux version for OSX or adjust the locations where syntax errors are thrown to match the slightly different dump file syntax of 6.97.

@Johann Widera: Brother use file name with .dat extension

There is an error coming up, which I coul not solve by myself. Maybe you have some suggestions.
When ever I run this code in my MATLAB script this is shown:

Error using Model.Blade.XFOIL.Xfoil (line 184)
Unable to read xfoil output file Xfoil_a03.000_dump.dat

Apart from that everything is running smoothly. Thanks

Does anyone knows what are the outputs like UeVinf,
Dstar, Theta, H mean and why does x, y , s, Cf and theta has entries for even x >1.


I found a solution to prevent XFOIL from popping up. Bellow ''% Write xfoil command file'' type this command:


Kirk Lewis

Scrap that I figured it out! my cmd line was wrong, changed it to:

cmd = sprintf('cd %s && /Applications/ < xfoil.inp > xfoil.out',wd);

and that worked.

Kirk Lewis

HeyNicolò Sanfelici,

I'm also running on Mac but I can't get it to work. I changed the code at line 166 to:

cmd = sprintf('open -a /Users/kirklewis/Desktop/xfoil/Xfoil',wd);

and Xfoil opens, but it won't run any of the commands. I'm thinking it might be due to the version I've got, as above it states you require Xfoil 6.99 but the mac version I've got is 6.97. Did you figure out a way to update your Xfoil or have you also got 6.97?

Great work there. Let us know in case you find a way to keep the pop-ups away.

It works also on mac! at line 162, instead of xfoil.exe, I have written
A copy of must be in the same directory as this m function.

I'm running the examples
"foil = xfoil('NACA0012',10,1e6,0.2,'oper/vpar n 12')"
"[pol foil] = xfoil('NACA0012',10,1e6,0.0,'panels n 330')"
"[pol foil] = xfoil('NACA0012',5,1e6,0.2,'oper iter 50')"
but keep getting the message
"Index exceeds matrix dimensions.
Error in xfoil (line 229)
pol.xtrf_top = P{1}(1);
what am i doing wrong?


Dylan Mack

Does this work for Mac? (comments in the primary .m file suggest that the an xfoil.exe needs to be within the directory)

Louis Edelman


The way the interface works i that it creates an input file and then parses and output file. As written that input and output file name is static in the code. However, you could procedurally generate the filenames (random number generator maybe) by modifying the file creation and reading lines of code using the eval function and sprintf, then wrapping several instances of the function call in a parfor loop. I may just try fiddling with the code to make that work myself if I find some time in the next week or so. Please do update me if you end up parallelizing the interface yourself.

When I was doing optimization work with this code, I tended to just let it run before lunch and came back in a few hours.


Hi Louis,
First of all, great work of yours!!
I am currently using your XFoil interface to optimize airfoils, for example by coupling it with a GA. Relating to this, I have the following questions.

1). Since I have to use the GDES Lera and PPAR N commands, the XFoil windows pop up, although I am also using the plop G command. Is there a way to make the XFoil programm work in the Background / invisible?
2). It would be a great speed up if I could make the GA work in parallel. However, the code throws the following error: "The process can't access the file, because it is used by another process" and "Error using "xfoil (line 166)
Xfoil execution failed! cd X:\~ && xfoil.exe < xfoil.inp > xfoil.out" ". Would there be a way to prevent this/make the interface parallel?


foil.x and foil.y are the panel coordinates that the ouptuts like displacement thickness and skin friction are calculated at. The line behind the foil is the wake that XFOIL adds so that it can estimate viscous drag by wake defect integration. You will notice that boundary layer properties are carried into this wake region if you plot these properties vs. foil.x.

As always, I suggest not using XFOIL and this interface as a magic black box. It is best to understand at least conceptually that it is a panel code with a integral method boundary layer estimator.


Louis, are the results foil.x and foil.y supposed to be the geometry coordinates for the airfoil? I find that get a non-normalized array for the two. I get a 182x1 double for foil.x and foil.y, with foil.x having values > 1.0

When I plot I get an airfoil shape with a random line at the trailing edge. Is this supposed to happen? Seems like if both arrays were 160 long the airfoil shape would make sense.

Louis Edelman


The extra commands are essentially lines of xfoil input commands entered as a series of strings after the required inputs of geometry, alpha, Re, Mach.

E.g. xfoil('NACA0012',[-5:15],1e6,0.2,'oper iter 150','gdes flap 0.6 0 5 exec')

which extends the iteration max to 150 and deflects a 60% chord flap by 5 degrees. (note the exec)

There is no MATLAB parsing of these commands, they are passed directly to xfoil and should be in the appropriate syntax. Refer to the XFOIL documentation and figure out the series of commands necessary to do what you want.

This code is an interface, not a replacement for understanding XFOIL commands and processes.

90% of the time, the problem is a misunderstanding of what is acceptable for XFOIL so be sure to check it's documentation.

I am not able to use extra commands. Anyone else who has encountered this problem? Is there a more elaborate description on how to use extra commands somewhere?

Louis Edelman

A note to users: If you do not see an Xfoil window pop-up when you execute and then you get a read error for one of the dump files, you've got a problem with your profile. The most common problem is that Xfoil doesn't accept airfoils with more than 494 panels. Use ppar in xfoil or interp1 in MATALB to downsample your geometry and create a new .dat or nx2 array.

Textscan errors are probably due to 1) not using Xfoil 6.99 (dump file format changes) or using a version of MATLAB older than R2014b (textscan changes).

Hi everyone, I use ubuntu version 14.04 and xfoil 6.97.
And I was with same problem with geometry of file (error textscan)..and according recomendantion of Louis.
I change the pair-value of 'HeaderLines','2' to 'HeaderLines','3' in line 262 .. and it works!

Brendon M


I am trying to pass xfoil.m a double of nx2 coordinates beginning from the top TE to the LE and then to bottom TE. xfoil.m will only return empty polar values of CL or CD etc. Is there something that I am missing? The sub-function works fine if you pass a string like 'naca2412', but not when passed the coordinates.


Hi everyonr,
When I run this code, I find that the pressure distribution is always NAN. can you help please to solve this problem?


I am trying to use your m file in linux too. Do ı need make any modificaitons? I have just renamed xfoil.exe as xfoil. I will send the airfoil coordinates file.

There are three things it could be:
1) Your geometry file isn't formatted correctly. Open it up as a text file and see if it is in neatly delimited in two columns with the airfoil name in the first line. Remember, you can also enter a nx2 matrix of airfoil (x, y) coordinates from the matlab workspace instead of importing the text file.
2) If fixing the geometry file doesn't fix it, ensure you have to correct version of Xfoil, 6.99
3) If none of that works, send me the geometry file at and I will see what I can do.


I would like to use this program with another foil geometry, but I don't know how to specify number of digits in the textscan formspec for throwing the error. Could you please help me? Which textscan functions must be rebuilt? I am using R2016a by the way.

Louis Edelman

Please note: Usage with some older versions of textscan may throw floating point errors on some airfoils. If possible upgrade to 2014a or higher. If that isn't possible, manually specify the number of digits in the textscan formspec throwing the error.


Added a version of the function that targets specific Cl values instead of alpha. This is virtually identical to the origninal script and I wrote it a few years back when I did the original. I'm 90% sure it is debugged, but some probably still exist.

Fixed file rename that occurred at last update.

Added warning if one or more requested alpha values fail to converge.

MATLAB Release Compatibility
Created with R2014b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: Xfoil Interface