File Exchange

image thumbnail

Xfoil for matlab

version (70.7 KB) by Luca Virtuani
Xfoil rewritten as MATLAB script


Updated 17 Mar 2015

View License

I developed this script some time ago and today i decide to make it available here. All functions are simply translated from fortran to matlab so the times for a single calculation are much greater than the XFoil source.
If someone manage to improve the code let me know, because I’ve been busy with other projects.
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

Comments and Ratings (10)

Hi Luca,
Why it is slow to finish the run. It took 32 sec on my station. Is there a way to specify the output


I code has an error on line 229
after some trails and errors (much more of course) I successfully ran the code.
just change the numbe
P = textscan(fid,' xtrf =%f (top) %f (bottom)','Delimiter',' ','MultipleDelimsAsOne',true,'CollectOutput',1,'HeaderLines',2); % this last number is modified from 3 to 2

It works now;
hope will work 4 u 2
r 3 to 2 in that line an d also to the line

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

Can this be used in tandem with the fmincon function for an optimization algorithm?

Scott Bollt

For anyone trying to input your own airfoil data and getting bad results, make sure you check the endpoints of your input data and compare that to the data of the file they are using. The program does not seem to play well with data that is exactly zero at the ends so make sure you give it a tiny offset, and make sure the data starts at X=1 and ends at X=1.

This code works well for me, I'm currently working on embedding it in a loop for multiple foils at a range of AoA's.

Hi there,

I'm trying to import data to matlab to run simulations on a folder of NACA airfoils, but the code stops at line 88 of your function.
Here is the error I get. . .

Field assignment to a non-structure array object.

Error in xfoil>ggcalc (line 8384)

Error in xfoil>specal (line 8171)

Error in xfoil (line 88)

Error in main_new (line 28)

Can you explain what the specal function does as that appears to be where the code dislikes the way p is structured. . .

Any ideas?

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

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor