File Exchange

image thumbnail


version (11.5 KB) by Rafael Oliveira
Class interface between XFOIL and MATLAB, with the ability of running many instances in parallel.


Updated 29 Jul 2016

From GitHub

View Version History

View license on GitHub

Class interface between XFOIL and MATLAB, with the ability of running many instances in parallel.

Cite As

Rafael Oliveira (2021). rafael-aero/XFOILinterface (, GitHub. Retrieved .

Comments and Ratings (57)

Abdulaziz Abutunis

Do you have any advice on how to toggle the CINC in xfoil so the minimum Cp is added to the polar file

From the Xfoil document " CINC Toggle minimum Cp inclusion in polar"

Your code segment related to this is

function addPolarFile(this,PolarFile)
this.addActions({'PACC'; PolarFile; ''});
this.PolarFiles{end+1} = PolarFile;

function addPressureFile(this,PressureFile)
this.addActions(sprintf('CPWR %s', PressureFile));
this.PressureFiles{end+1} = PressureFile;
function addClosePolarFile(this)
I have tried several attempts but could not


Abdulaziz Abutunis

Abdulaziz Abutunis

Thanks, Rafael for the program again and wish you would answer my this time. I am looking to extract the minimum pressure coefficient Cp or even the pressure coefficient data on the airfoil in such way you have done with Cl and Cd (e.g., p1.CD and p1.CL)

Really need your help!

yu haibo

sree N

Reshma kalagara

Hi Rafael,

Thank you for this amazing program. Is there a way to get L/D and Cpmin values in polar.txt file since i am doing an optimisation and i would like to use this values. Thank you.


Tim Harms

Tim Harms

Hi Rafael,

So far everything works fine for me so that's awesome! Is there a way to surpress the xf = statement? I'm trying to do an optimisation and I'd like to plot my progress instead of useless (for me at least) statement.


Felipe Kurcewicz


Dylan Mack

Is this interface available for Mac in any way? Other downloading platforms say this interface works for Mac OS X, however the error "Unix version not yet implemented!" shows whenever I try to use the interface.

Abdulaziz Abutunis

Hi armando pirlo have you solve this problem, if so please what have you done to solve the problem.
Error using textscan
HeaderLines must be integer-valued.
Error in Airfoil (line 34)


Martin Carrizales

Hi Rafael.

I'm using the R2017a version, and apparently, their a change using the textscan function and the error that trow is:
Error using textscan
Invalid file identifier. Use fopen to generate a valid file identifier.

Error in Airfoil (line 24)
tmp=textscan(Header, '%f%f','MultipleDelimsAsOne',true);

Error in exampleXFOIL (line 7)
xf.Airfoil = Airfoil('SC(2)-0610 AIRFOIL.dat');
Apperently even if you change the value from "TRUE" to "1", in line 24, it still not working.

I dont know if you have any idea on how to fix it


Anders Forslund

Abdulaziz Abutunis

Hi Rafael,

Thank you for the amazing program. i wonder if the viscous solution is on of off in this code. if it is of, is there a way to consider the viscous solution only.

Best Regards,

Henry Jiang

Hi Rafael,

Do you have any updates on the error stated by eren karaca earlier? I realized that the code still works provided it is running on an older version of MATLAB, and not a newer version.


Martin Kurien

er, I may be wrong about that since the fix doesn't quite work. I know that I haven't been able to get importing from a .dat file to work with a NACA0012 that I got from Airfoil Tools. It isn't a big deal since I can always generate it, but It seems weird that there is a problem.

Martin Kurien

I found an error in lines 52 and 53 in the Airfoil Class. The indexing is given as iLE:-1:1, when it should be end:-1:iLE.

eren karaca

Hi Rafael,
The code works perfect until i receive the following errors;

Error using XFOIL/readPolars (line 27)
Invalid polar file Polar.txt

Error in exampleXFOIL (line 55)

Are there any solution you may offer?
Thanks so much!

Russell Woo

Hi Rafael,
This interface is so great and very useful!
When I load my design airfoil.dat ,it show me some errors.
error fgetl (line 33)
[tline,lt] = fgets(fid);

error Airfoil (line 23)
Header = fgetl(fid);

error exampleXFOIL (line 7)
xf.Airfoil = Airfoil('2412-1.dat');

I am a new guy to use the matlab.My matlab version is 2016b.
Can you solve this problem? appreciate~~~

Rafael Oliveira

Hi Nicolas,
you can try this:

for alpha = 0:0.1:25
xf.addActions(sprintf('CPWR alpha_%f.txt',alpha));

Nicolas Lavalette

Hi Rafael,
Do you know how I can extract the Cp values computed by XFoil for a single set of parameters ?
Thanks for your help and your program !

Thang Le Duc

armando pirlo

Hi Rafael,
with your tips the code works.
I use the versione R2015b.


Rafael Oliveira

Hi Armando,

which version of MATLAB are you using? It seems that textscan has changed since I published this code, try replacing the lines with
HasHeader = false;
HasHeader = true;

in the Airfoil.m code with
HasHeader = 0;
HasHeader = 1;

And letting me know if it works!

armando pirlo

Hi Rafael,
I'm trying to import .dat file with coordinates of an airfoil but when i start the script i get an error:

Error using textscan
HeaderLines must be integer-valued.

Error in Airfoil (line 34)
Coordinates = textscan(fid, '%f%f','HeaderLines',HasHeader,'MultipleDelimsAsOne',true);

Error in exampleXFOIL (line 10)
xf.Airfoil = Airfoil('MH_115.dat');

The MH_115.dat file is a standard two column text file in the Selig format (you ask the Eppler format but it's the same, right?).

Thanks for the code.

George Paschalis

Hi Rafael,

Thanks a lot, works great. I tried doing it through:
xf.changePaneling(80); %Change number of panels

but with not much luck. Although it does run faster.

Thanks for making the code as well man! ;)

Rafael Oliveira

Hi George,
You can reinterpolate the coordinates of the airfoil using the pchip function from MATLAB, something like:

af.UpperY = pchip(af.UpperX, af.UpperY,linspace(af.UpperX(1),af.UpperX(end),200));
af.UpperX = linspace(af.UpperX(1),af.UpperX(end),200);

and then the same for the LowerX / LowerY coordinates.

George Paschalis

Hi Rafael,
Is there a way to change the number of panels (or number of airfoil points) for an imported airfoil?

Wenxiang Ding


Marvin Katende

Rafael, can you please help me with your matlab coding? I need to compare them with mine: same naca number. Thanks

Abdulaziz Abutunis

This is a great work

Tom Clark

This is seriously very good.

So good its annoying how much time I put into my previous solution :(

It could do with better commenting within the source for maintainability and better description of the inputs - but people familiar with xfoil should pick it up pretty quickly.

Frustrating that it doesn't run on unix - if I get some time I'll update and share the code back.

Thanks rafael!

Gregory Vernon


I've used XFOIL-MATLAB interface with R2014a with no problems, it's been great! However, I just upgraded to R2014b and, when reading my own airfoil .dat file, I get the error:

Error using textscan
HeaderLines must be integer-valued.

Error in Airfoil (line 35)
Coordinates = textscan(fid, '%f%f','HeaderLines',HasHeader,'MultipleDelimsAsOne',true);

Changing line 26 of Airfoil.m to "HasHeader=1" instead of "HasHeader=true" seems to fix the problem. I'm not sure why, as those two statements should be equivalent.



how can i develop interface for 'INTE'..?

Lucas Augusto

hey, i'm having this problem:
>> exampleXFOIL
Cannot find an exact (case-sensitive) match for 'XFOIL'

The closest match is: xfoil in C:\Users\Lucas94\Documents\MATLAB\xfoil.m

Error in exampleXFOIL (line 2)
xf = XFOIL;
Could anyone help me?


Thanks for the awesome interface!

I am though, facing some issues when trying to paralell processing XFOIL in a program, using parfor loops. Could you give me some tips or a guide on how to simultaneosly run more than one airfoil analysis at the same time? Thanks!


I am a masters student of aeronautics at Durham finding this very useful, is it possible to print the tables of the results as i then need to to use the nubers to generate lift profiles. Any help would be great I am not all to familiar with matlab.

Brett Behrends

2 questions for you. I have been trying to get the program to print a pressure file, specifically a CPWR file. I saw that you already have the framework for it in the XFOIL.m file, but I'm have trouble getting the commands right. Also, I would like to cycle through a couple of different airfoils in the program. How would I do that?

Rafael Oliveira

Hi Matt,
To hide the xfoil window, just set (assuming x = XFOIL;)
x.Visible = false;
Any other doubts, drop me an email!

Matt Brown

Is there any way to supress the xfoil window? I implemented this into a loop and the repeated open/close of xfoil gets to be a bit much.

Other than that, good code!


Hi Rafael,

I shot another email to your listed mailbox. Thanks.


Rafael Oliveira

Hi Mingyao,

The delete command in this case is used to delete the files whose names are stored in the cell array PolarFiles

This cell will have inside something like this:
PolarFiles = {'file1.txt', 'file2.txt', 'file3.txt'};

This is a common misunderstanding with MATLAB, about the difference between a cell array and a normal array of numbers, and how to access the elements. In the case of a cell array, you can access the content using {index}, and a sub-part of the cell as (index).
For example, let's say you have:
>> PolarFiles = {'file1.txt', 'file2.txt', 'file3.txt'};

Then, if you run:
>> PolarFiles(2)
ans = {'file2.txt'} % Returns a cell array with one element

>> PolarFiles{2}
ans = 'file2.txt' % Returns the string that was stored in the cell

If you have any further doubt, send me an email and I can answer you directly!


Hi, Rafael! Thank you for your response. I think what I don't really understand about the code is the 'delete' command. I tried a search in MATLAB Help, but the same command seems intended to delete files located in a folder or a handle object. If I simply try to delete a cell in the command window like this, MATLAB will complain. Could you please shed light on the subject? Thanks.

Rafael Oliveira

Hi! This part of the code is used to delete any polar files that might exist from previous runs, so that when XFOIL is run a few lines later, with:

this.Process = PB.start;

We can be sure that the polar files are going to be created due to this run, and not previous results. This happens very often when making small modifications in the airfoil that affects the XFOIL convergence, so that you can have a mix of old and new results.


Would you be so kind as to explain what the following lines of your code do? Thanks.

for i=1:length(this.PolarFiles)

Rafael Oliveira

Hi Matthias, I know I've already answered you, but I'll copy it here as a reference for other people:

xFlap = 0.6;
yFlap = 0;
FlapDeflection = 5;

xf = XFOIL;

% Create a NACA 5-series airfoil
xf.Airfoil = Airfoil.createNACA5('23012',150);

% Add a flap deflection to the airfoil
xf.addActions(''); %Simulate an enter, to get out of GDES mode


Thanks a lot,
could you help me with implementing trailing edge deflection?



I look that you kill Xfoil when it freezes.
Do you know that happen so that Xfoil freezes ?

Rafael Oliveira

I just implemented what I needed for my project, but you can use the XFOIL.addActions('') to send custom commands to it (just do what you want in an XFOIL section, and take note of the commands you typed).
If you have a list of commands you need, I can try to implement it into the class too...

Please include more of the common xfoil features .... Thx (:

thank you so much my friend. I saved a lotttttttttt of time using this.. Thnx. Big FAN (:

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

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!