Code covered by the BSD License  

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
XFOIL - MATLAB interface

4.6 | 14 ratings Rate this file 139 Downloads (last 30 days) File Size: 11.6 KB File ID: #30478 Version: 1.0
image thumbnail

XFOIL - MATLAB interface


Rafael Oliveira (view profile)


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

| Watch this File

File Information

I developed this interface some time ago, so I finally decided to refine and make it available here. It provides an interface between XFOIL and MATLAB, creating the files required by XFOIL to run, and reading the results back in an easy to access polar structure.

As the goal was to perform airfoil optimization, this interface is capable of parallel execution, so that you can create multiple instances and run all at the same time, without blocking MATLAB. Also, it is possible to hide the plotting window, so XFOIL will not interrupt your work-flow while it is running.

A simple example script using an NACA 23012 is provided, showing the main features of the interface.

XFOIL is not included on this package, but the class will download and extract it for you automatically in case the XFOIL executable is not available in your path.

XFOIL is an analysis software provided by Prof. Mark Drela (from MIT), for the design and analysis of subsonic airfoils. For more info, check his website at


Naca 4 Digit Airfoil Generator and Naca 5 Digit Airfoil Generator inspired this file.

MATLAB release MATLAB 7.11 (R2010b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (34)
22 Apr 2016 armando pirlo

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


Comment only
22 Apr 2016 Rafael Oliveira

Rafael Oliveira (view profile)

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!

Comment only
22 Apr 2016 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.

Comment only
20 Apr 2016 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! ;)

Comment only
20 Apr 2016 Rafael Oliveira

Rafael Oliveira (view profile)

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.

Comment only
20 Apr 2016 George Paschalis

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

Comment only
18 Apr 2016 Wenxiang Ding  
02 Feb 2016 Andrea

Andrea (view profile)

02 Oct 2015 Marvin Katende

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

14 Aug 2015 Abdulaziz Abutunis

This is a great work

14 Jul 2015 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!

05 Dec 2014 Gregory Vernon  
03 Dec 2014 H E

H E (view profile)

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.

31 Oct 2014 Arash

Arash (view profile)

30 Jul 2014 SREEJITH

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

29 Apr 2014 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?

Comment only
15 Jan 2014 Guilherme

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!

02 Dec 2013 James

James (view profile)

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.

Comment only
08 Feb 2013 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?

Comment only
11 Oct 2012 Rafael Oliveira

Rafael Oliveira (view profile)

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

Comment only
11 Oct 2012 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!

03 Mar 2012 Rajesh Senthil Kumar  
21 Feb 2012 Mingyao

Hi Rafael,

I shot another email to your listed mailbox. Thanks.


Comment only
21 Feb 2012 Rafael Oliveira

Rafael Oliveira (view profile)

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!

Comment only
20 Feb 2012 Mingyao

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.

Comment only
20 Feb 2012 Rafael Oliveira

Rafael Oliveira (view profile)

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.

Comment only
18 Feb 2012 Mingyao

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

for i=1:length(this.PolarFiles)

Comment only
29 Nov 2011 Rafael Oliveira

Rafael Oliveira (view profile)

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

Comment only
24 Nov 2011 Matthias

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

Comment only
24 Nov 2011 Matthias  
28 Jul 2011 toto13000

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

Comment only
07 Mar 2011 Rafael Oliveira

Rafael Oliveira (view profile)

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...

Comment only
06 Mar 2011 sunil anandatheertha

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

Comment only
06 Mar 2011 sunil anandatheertha

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

Contact us