Get from Ico-github-logo

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

» Watch video

Highlights from

  • Airfoil
  • exampleXFOIL.m
    Create a new instance of the XFOIL class, and set some properties
  • View all files
4.6 | 17 ratings Rate this file 55 Downloads (last 30 days) File Size: 9.77 KB File ID: #30478 Version: 1.1
image thumbnail



Rafael Oliveira (view profile)


21 Feb 2011 (Updated )

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

| Watch this File

File Information

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


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 (43)
24 Feb 2017 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,

Comment only
11 Jan 2017 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.


Comment only
21 Dec 2016 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.

21 Dec 2016 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.

Comment only
24 Nov 2016 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!

Comment only
17 Nov 2016 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~~~

28 Jul 2016 Rafael Oliveira

Rafael Oliveira (view profile)

Hi Nicolas,
you can try this:

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

Comment only
27 Jul 2016 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 !

Comment only
06 Jun 2016 Thang Le Duc

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 (:

29 Jul 2016 1.1

Fixed the URL to download XFoil automatically

Contact us